#32704: Unexpected behavior of .defer() and .only()
-------------------------------------+-------------------------------------
Reporter: Manuel | Owner: nobody
Baclet |
Type: Bug | Status: new
Component: Database | Version: 3.1
layer (models, ORM) |
Severity: Normal | Keywords: defer only
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Considering a simple `Company` model with four fields: `id`, `name`,
`trade_number` and `country`. If we evaluate a queryset containing a
`.defer()` following a `.only()`, the generated sql query selects
unexpected fields. For example:
{{{#!python
Company.objects.only("name").defer("name")
}}}
loads all the fields with the following query:
{{{#!sql
SELECT "company"."id", "company"."name", "company"."trade_number",
"company"."country" FROM "company"
}}}
and
{{{#!python
Company.objects.only("name").defer("name").defer("country")
}}}
also loads all the fields with the same query:
{{{#!sql
SELECT "company"."id", "company"."name", "company"."trade_number",
"company"."country" FROM "company"
}}}
In those two cases, i would expect the sql query to be:
{{{#!sql
SELECT "company"."id" FROM "company"
}}}
In the following example, we get the expected behavior:
{{{#!python
Company.objects.only("name", "country").defer("name")
}}}
only loads "id" and "country" fields with the following query:
{{{#!sql
SELECT "company"."id", "company"."country" FROM "company"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32704>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.5204502c627fa14d76e7586f91e07305%40djangoproject.com.