Repository navigation
Django 5.2 compatibility: prefetch related rely on TupleIn lookup - #513
ddesvillechabrol wants to merge 3 commits into
Conversation
33e516e to
af8ca5d
Compare
| { | ||
| ( | ||
| where.lhs.alias, | ||
| attnames, |
There was a problem hiding this comment.
I very much suspect this don't be invalidated properly. Need to simulate conj for these, i.e a == 1 & b == 2
There was a problem hiding this comment.
Yes you were right, the invalidation doesn't work. I tried something that work but the information is duplicated. Maybe I should take into account that the children is a tuple lookup to be able to transform it as an AND condition to have the conj like you said a=1&b=2. I will check that next monday I think
There was a problem hiding this comment.
Hello ! I found some time today. The TupleIn conj is like the AND conj and it's well invalidated if the instance is updated 😄
Tell me if you see any other issues 🙏
| from django.db.models.sql.where import NothingNode | ||
| from django.db.models.lookups import Lookup, Exact, In, IsNull | ||
| from django.db.models.expressions import BaseExpression, Exists | ||
| from funcy import cat, group_by, join_with, lcat, lmap |
|
|
||
|
|
||
| class OrderLineItem(models.Model): | ||
| pk = models.CompositePrimaryKey("product_id", "order_id") |
There was a problem hiding this comment.
Should use if to make it work (be skipped) in older versions
|
Hello, thanks for the PR. Can you please attend to the comments above. Also I see that tests are failing |
since django 5.2 with the CompositePrimaryKey, prefetch related seems to use TupleIn and ColPairs to get prefetch querysets and dnf key part used in conj is lost
af8ca5d to
0c1d8a7
Compare
|
Yes I use feature only available for django 5.2+ so all test with django version before 5.2 failed and sorry for the auto formating 🙏 |
8e1edc8 to
c0fb686
Compare
Hello,
I experienced some issues with django 5.2 with prefetch related cache. Some prefetch related items in cache were not retrieved because the dnf part of conj keys was not set. Since django 5.2, the
get_prefetch_querysetrelies on Tuple Lookup since this commit django/django@626d77e .The tuple lookup is used by composite primary keys newly introduced in django 5.2, sorry I don't have time to add every tuple lookup. So, I only added the TupleIn lookup that is used by prefetch related and I added a test with a composite primary key to check that TupleIn is taken into account by dnfs.
After the review, the composite key's conj key is set like
conj:tests_orderlineitem:product_id=1&order_id=A75HPrefetched items with unique keys keep the same conj ie:
conj:test_order:order_id=A75HThanks !
Dimitri