#24002: .filter(generic_rel=val) should filter on related model primary key
value,
not the object_id value
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: master
layer (models, ORM) | Keywords:
Severity: Normal | Has patch: 1
Triage Stage: Accepted | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Doing `Publisher.objects.filter(book=1)` currently produces a query with
`WHERE book.object_id = 1` (assuming book is GenericRelation field). That
is, the filter targets object_id field of book. Filtering on reverse side
of a foreign key relation does however target the primary key field of the
related model. Similarly aggregating over generic relation targets the
object_id field, not the primary key field.
The most problematic case is doing a query like
`Publisher.objects.filter(book=somebook.pk)`. This doesn't work correctly
with generic relations, but works nicely with reverse foreign key
relations.
Unfortunately fixing this changes behavior of currently working code, and
I can't think of any sensible way to do this with backwards compatibility
period. So, I suggest we just treat this as a bug fix for master.
--
Ticket URL: <https://code.djangoproject.com/ticket/24002>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.65e7a5ee1a5a966dd9c6daf003a86bda%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.