--
Ticket URL: <https://code.djangoproject.com/ticket/16127>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Database layer (models, ORM) => Core (Serialization)
* needs_tests: => 0
* needs_docs: => 0
* stage: Unreviewed => Accepted
Old description:
New description:
--
--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:1>
* ui_ux: => 0
Comment:
This bug report should be simplified with a simpler model and view as
given below.
models.py:
{{{
class Person(models.Model):
name = models.CharField(max_length=50)
phone = models.CharField(max_length=13)
}}}
view.py:
{{{
objects = Person.objects.defer('phone')
data = serializers.serialize('json', objects, ensure_ascii=False)
return HttpResponse(data, mimetype="application/javascript")
}}}
Output:
{{{
[{"pk": 1, "model": "ticket.person_deferred_phone", "fields": {}}]
}}}
Specifying fields to the serializer like below, gives the same result.
{{{
data = serializers.serialize('json', objects, ensure_ascii=False,
fields=('name',))
}}}
The same issue also applies when using .only().
I would argue that when fields are not specified to the serializer, the
entire object should be loaded and serialized.
--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:2>
Comment (by knutz3n):
A test for this issue can be found at
https://github.com/knutz3n/django/commit/3339f94a8bb4162f9ea650a935917f004726a9a8.
--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:3>
Comment (by knutz3n):
The bug seems to apply to all serializers, not only JSON.
--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:4>
Comment (by monikasulik):
I tested this on the current master branch and this no longer seems to be
a problem.
--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:5>
* status: new => closed
* resolution: => worksforme
--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:6>