Opened 13 years ago
Closed 13 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)
Change History (7)
comment:1 by , 13 years ago
Component: | Core (Serialization) → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:2 by , 13 years ago
Has patch: | set |
---|
follow-up: 5 comment:3 by , 13 years ago
Did you purposely left the first occurrence of "Django objects" in the first paragraph?
by , 13 years ago
Attachment: | serialization-clarification.diff added |
---|
comment:5 by , 13 years ago
Triage Stage: | Accepted → Ready 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 , 13 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.