From 0527e22a242e2cd1cdc7bd8260bc81d0a3b48b01 Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Sat, 26 Sep 2020 19:05:11 +0700 Subject: [PATCH] Fix annotations introspection in Django 3.0 --- cacheops/tree.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cacheops/tree.py b/cacheops/tree.py index 40f8e2ab..f7737e23 100644 --- a/cacheops/tree.py +++ b/cacheops/tree.py @@ -130,7 +130,8 @@ def table_for(alias): if qs.query.annotations: subqueries = ( # Django 3.0+ sets Subquery.query - query_dnf(getattr(q, 'query', q.queryset.query)) for q in qs.query.annotations.values() + query_dnf(getattr(q, 'query', None) or getattr(q, 'queryset').query) + for q in qs.query.annotations.values() if type(q) is Subquery ) dnfs_.update(join_with(lcat, subqueries))