Code

Opened 6 years ago

Closed 6 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: UI/UX:

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)

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #5711

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.