#4789: select_related + depth gives wrong result
---------------------------------------------------+------------------------
Reporter: Gábor Farkas <[EMAIL PROTECTED]> | Owner: adrian
Status: new | Component:
Database wrapper
Version: SVN | Resolution:
Keywords: select_related, depth | Stage:
Unreviewed
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
---------------------------------------------------+------------------------
Changes (by Gábor Farkas <[EMAIL PROTECTED]>):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
after examining the code more, it seems that i was wrong with what i wrote
in note 3.
we can think like this:
i specified depth=1. that means, it should query the data from the
Subscriber model (because that's the model i'm querying), and also data
from the User and the Newsletter models.
but if i examine the generated sql, it also contains the group-data. the
sql-query starts with:
{{{
SELECT-
"main_subscription"."id",
"main_subscription"."user_id",
"main_subscription"."newsletter_id",
"main_user"."id",
"main_user"."group_id",
"main_group"."id",
"main_group"."team_id",
"main_newsletter"."id",
"main_newsletter"."name"
}}}
and this is already wrong, because after this query, django is creating
the objects for this data,
sequentially 'consuming' the data returned by the sql-query.
so it creates the Subscription object using the first 3 field-data, then
the User using the next 2 field-data,
and then goes on to create the Newsletter using the next 2 field-data, but
that becomes wrong,
because at that position the sql contains the Group-data.
so now the question becomes:
why does django generate this sql-query?
--
Ticket URL: <http://code.djangoproject.com/ticket/4789#comment:1>
Django Code <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---