You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. This seems like a bug, as I couldn't find anything in the documentation which would explain it. I could create a pull request with a failing test if this does need fixing.
What happened?
The cache for a query was not invalidated, when it should have been. The query contains an annotation and subsequent filter based on querying a ManyToMany field for which the related manager had been modified since the last query.
Interestingly the problem does not occur when filtering on the query directly, rather than using an annotation and filtering against that:
defall_orders_good(user): # correctly re-queries after change to User.ordersmanaged=user.orders.all().values_list("pk", flat=True)
returnOrder.objects.filter(pk__in=managed)
Steps to reproduce
As above, running on Ubuntu 22.04, Django Version 4.2.5, Python 3.11, Postgres 14.10, Cachalot 2.6.2.
In case you're wondering why I'm filtering in this unusual way, this is a much simpler version of a more complicated all_orders() method which queries some other tables too.
The text was updated successfully, but these errors were encountered:
sdolemelipone
changed the title
Query which filters on annotation of second query does not have cache invalidated after second query would be invalidated.
Query which filters on annotation of second query does not have cache invalidated
Feb 23, 2024
Hi. This seems like a bug, as I couldn't find anything in the documentation which would explain it. I could create a pull request with a failing test if this does need fixing.
What happened?
The cache for a query was not invalidated, when it should have been. The query contains an annotation and subsequent filter based on querying a ManyToMany field for which the related manager had been modified since the last query.
With models as follows:
and evaluating the queryset returned by the following method:
What should've happened instead?
The cache for the top level query should have been invalidated:
Interestingly the problem does not occur when filtering on the query directly, rather than using an annotation and filtering against that:
Steps to reproduce
As above, running on Ubuntu 22.04, Django Version 4.2.5, Python 3.11, Postgres 14.10, Cachalot 2.6.2.
In case you're wondering why I'm filtering in this unusual way, this is a much simpler version of a more complicated
all_orders()
method which queries some other tables too.The text was updated successfully, but these errors were encountered: