Opened 12 years ago

Closed 12 years ago

#18214 closed Cleanup/optimization (fixed)

Serializers do not serialize iterators

Reported by: Moritz Sichert Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords: serialization json xml
Cc: alex.ogier@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

According to serialization documentation the given object "can be any iterator that yields Django objects, but it'll almost always be a QuerySet". But it does not work with iterators.

Example:

>>> from django.core import serializers
>>> json_serializer = serializers.get_serializer('json')()
>>> json_serializer.serialize([1, 2, 3])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "trunk/django/core/serializers/base.py", line 46, in serialize
    concrete_model = obj._meta.concrete_model
AttributeError: 'int' object has no attribute '_meta'
>>>
>>> xml_serializer = serializers.get_serializer('xml')()
>>> xml_serializer.serialize([1, 2, 3])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "trunk/django/core/serializers/base.py", line 43, in serialize
    self.start_object(obj)
  File "trunk/django/core/serializers/xml_serializer.py", line 42, in start_object
    raise base.SerializationError("Non-model object (%s) encountered during serialization" % type(obj))
SerializationError: Non-model object (<type 'int'>) encountered during serialization

One should either change the documentation or make this work.

Attachments (1)

serialization-clarification.diff (1.2 KB ) - added by Alex Ogier 12 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Claude Paroz, 12 years ago

Component: Core (Serialization)Documentation
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

that yields Django objects. [1, 2, 3] are not Django objects. Accepting on the base that what are Django objects might be more clearly explained in the documentation.

comment:2 by Alex Ogier, 12 years ago

Has patch: set

comment:3 by Claude Paroz, 12 years ago

Did you purposely left the first occurrence of "Django objects" in the first paragraph?

comment:4 by Alex Ogier, 12 years ago

Cc: alex.ogier@… added

Good point, that wasn't deliberate.

by Alex Ogier, 12 years ago

in reply to:  3 comment:5 by Moritz Sichert, 12 years ago

Triage Stage: AcceptedReady for checkin

Replying to claudep:

Did you purposely left the first occurrence of "Django objects" in the first paragraph?

I did not realize that it reads 'Django objects'. Thank you for the hint!

comment:6 by Claude Paroz, 12 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top