On Wed, 2014-12-17 at 09:21 +0200, Anssi Kääriäinen wrote: > I investigated this a bit, and the problem is deeper in generic > relations handling. Even filtering on generic relations use the related > field's value, not the related model's primary key value. We should fix > that, too. > > Luckily the impact of the annotation case isn't that big. Even if the > target would have been the related model's primary key there aren't that > many sensible queries to run against the PK. > > The impact of changing the way .filter() works might be a bit bigger, > but I think we will need to do this as a bug fix. Case where queries > "worked" as in they produced results but the results were incorrect are > nasty to fix. Somebody is always relying on the incorrect results.
It turns out this is easy to fix. There is a patch for this at https://github.com/django/django/pull/3743. The generic relations still work a bit differently to that of reverse foreign key - where reverse foreign keys can be filtered with .filter(reverse_relation=some_related_object), that doesn't work with reverse relations, instead you have to explicitly provide the primary key value by doing .filter(generic_rel=some_related_object.pk). - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" 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]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1418804187.6766.35.camel%40TTY32. For more options, visit https://groups.google.com/d/optout.
