[Django] #16127: Queryset which uses defer() method not serialize in Json

13 views
Skip to first unread message

Django

unread,
May 30, 2011, 11:51:59 AM5/30/11
to django-...@googlegroups.com
#16127: Queryset which uses defer() method not serialize in Json
----------------------------+----------------------------------------------
Reporter: eguevara2012@… | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Database layer (models, ORM)
Version: 1.3 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
----------------------------+----------------------------------------------
Hello!
I have this function using json and a queryset with defer() method, but
the fields not target in queryset, i need only "id" and "nome":

models.py

class Pessoa(models.Model):
nome = models.CharField(max_length=50)
data_nascimento = models.DateField()
data_inclusao = models.DateField()
cpf = models.CharField(max_length=14)
telefone = models.CharField(max_length=13)
celular = models.CharField(max_length=13)

class Meta:
abstract = True

class Proprietario(Pessoa):
endereco = models.ForeignKey(Endereco)

def __unicode__(self):
return "%s, %s" % (self.nome, self.cpf)

views.py:

def load_proprietarios(request):
data =
serializers.serialize('json',Proprietario.objects.defer('cpf','telefone','celular','data_nascimento','data_inclusao',),ensure_ascii=False))
return HttpResponse(data, mimetype="application/javascript")

This is the output:

[{"pk": 1, "model":
"proprietario.proprietario_deferred_celular_cpf_telefone_data_inclusao_data_nascimento",
"fields": {}}]

Note that the "id" and the "nome" fields (class Proprietario / class
abstract Pessoa) does not appear after defer() method.

Regards.

--
Ticket URL: <https://code.djangoproject.com/ticket/16127>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 30, 2011, 12:25:12 PM5/30/11
to django-...@googlegroups.com
#16127: Queryset which uses defer() method not serialize in Json
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
eguevara2012@… | Status: new
Type: Bug | Component: Core
Milestone: | (Serialization)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by ramiro):

* 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>

Django

unread,
Jun 10, 2011, 6:45:04 AM6/10/11
to django-...@googlegroups.com
#16127: Queryset which uses defer() method not serialize in Json
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
eguevara2012@… | Status: new
Type: Bug | Component: Core
Milestone: | (Serialization)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by knutz3n):

* 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>

Django

unread,
Jun 10, 2011, 7:46:53 AM6/10/11
to django-...@googlegroups.com
#16127: Queryset which uses defer() method not serialize in Json
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
eguevara2012@… | Status: new
Type: Bug | Component: Core
Milestone: | (Serialization)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------

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>

Django

unread,
Jun 10, 2011, 7:47:45 AM6/10/11
to django-...@googlegroups.com
#16127: Queryset which uses defer() method not serialize
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
eguevara2012@… | Status: new
Type: Bug | Component: Core
Milestone: | (Serialization)
Version: 1.3 | Severity: Normal
Resolution: | Keywords:
Triage Stage: Accepted | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------

Comment (by knutz3n):

The bug seems to apply to all serializers, not only JSON.

--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:4>

Django

unread,
Jun 5, 2015, 10:12:52 AM6/5/15
to django-...@googlegroups.com
#16127: Queryset which uses defer() method not serialize
--------------------------------------+------------------------------------

Reporter: eguevara2012@… | Owner: nobody
Type: Bug | Status: new
Component: Core (Serialization) | Version: 1.3

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Jun 5, 2015, 10:13:34 AM6/5/15
to django-...@googlegroups.com
#16127: Queryset which uses defer() method not serialize
-------------------------------------+-------------------------------------
Reporter: eguevara2012@… | Owner: nobody
Type: Bug | Status: closed
Component: Core | Version: 1.3
(Serialization) | Resolution:
Severity: Normal | worksforme

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by monikasulik):

* status: new => closed
* resolution: => worksforme


--
Ticket URL: <https://code.djangoproject.com/ticket/16127#comment:6>

Reply all
Reply to author
Forward
0 new messages