Opened 17 years ago
Closed 17 years ago
#9389 closed (duplicate)
Cannot specify extra arguments when deserializing.
| Reported by: | johnnyleitrim | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Serialization) | Version: | 1.0 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I wrote my own custom serializer. I can pass my Serializer parameters when I make a call to it:
serializers.serialize("my_format", queryset, my_param = my_value)
I can get the value of my_param in my Serializer class.
However, I cannot do the same when deserializing. This is because the deserialize method in django.core.serializer.__init__.py does not accept any extra parameters:
def deserialize(format, stream_or_string):
"""
Deserialize a stream or a string. Returns an iterator that yields ``(obj,
m2m_relation_dict)``, where ``obj`` is a instantiated -- but *unsaved* --
object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
list_of_related_objects}``.
"""
d = get_deserializer(format)
return d(stream_or_string)
I think that this should be changed to allow for optional parameters:
def deserialize(format, stream_or_string, **options):
"""
Deserialize a stream or a string. Returns an iterator that yields ``(obj,
m2m_relation_dict)``, where ``obj`` is a instantiated -- but *unsaved* --
object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
list_of_related_objects}``.
"""
d = get_deserializer(format)
return d(stream_or_string, **options)
Note:
See TracTickets
for help on using tickets.
Duplicate of #5711