#12937: Select related() not working as of Beta
---------------------------------------------------+------------------------
Reporter: subsume | Owner: nobody
Status: new | Milestone: 1.2
Component: Database layer (models, ORM) | Version: 1.2-beta
Resolution: | Keywords:
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
---------------------------------------------------+------------------------
Changes (by russellm):
* stage: Unreviewed => Accepted
Comment:
Ok - this is a weird case of an old bug colliding with a new one.
This problem doesn't exist in Django 1.1, because we didn't allow reverse
select related lookups for OneToOneFields. However, we didn't prevent them
either - as logged by #10414, listing non-existent (oor non-supported)
fields in a select related doesn't actually raise an error. So in 1.1, the
query looks something like:
{{{
SELECT (fields)
FROM "myapp_basecontact"
LEFT OUTER JOIN "myapp_consumer"
ON ("myapp_basecontact"."consumer_id" = "myapp_consumer"."id")
INNER JOIN "myapp_program"
ON ("myapp_basecontact"."program_id" = "myapp_program"."id")
WHERE "myapp_consumer"."file" = foo ORDER BY "myapp_basecontact"."date"
DESC
}}}
Which is fine, but not as good as it could be.
In r12307, we added support for reverse select related fields. This means
that the 'IR_contact' and 'consumer_contact' fields now get expanded.
However, because we are following a reverse one-to-one field, and that
field forms an inherited link, the select_related is doing a forward
select related back onto the parent model. This is what causes the T5 and
T9 joins.
There are some tests for inheritance and reverse select related, so it's
not just as simple as inheritance being the problem, but it's in that
general ballpark.
There is a second problem hidden in here, which is the use of an INNER
JOIN for the non-nullable field joined on a nullable link. I think this is
a repeat of what is reported by #12819.
--
Ticket URL: <http://code.djangoproject.com/ticket/12937#comment:2>
Django <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.