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))