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
Django has a built-in check when the rhs of the query should return an empty queryset. It raises an EmptyResultSet and returns an empty list for the result. When you combine an EmptyResultSet query with_cte unfortunately, django-cte does not recognize it, and throws an error instead of returning an empty list.
-- queryset -- <CTEQuerySet []>
cte.query
SELECT "population_cte"."id", "population_cte"."year", "population_cte"."population" FROM "population_cte" WHERE "population_cte"."population"<= 10000000
--POPULATIONS QUERY :
Traceback (most recent call last):
File "<console>", line 1, in<module>
File "/Users/ahp/Desktop/cte_test/testapp/core/api.py", line 87, in empty_query_issue
print(
File "/Users/ahp/Desktop/cte_test/venv/lib/python3.9/site-packages/django/db/models/query.py", line 374, in __repr__
data = list(self[: REPR_OUTPUT_SIZE + 1])
File "/Users/ahp/Desktop/cte_test/venv/lib/python3.9/site-packages/django/db/models/query.py", line 398, in __iter__
self._fetch_all()
File "/Users/ahp/Desktop/cte_test/venv/lib/python3.9/site-packages/django/db/models/query.py", line 1881, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/ahp/Desktop/cte_test/venv/lib/python3.9/site-packages/django/db/models/query.py", line 99, in __iter__
model_cls = klass_info["model"]
TypeError: 'NoneType' object is not subscriptable
Django has a built-in check when the
rhs
of thequery
should return an emptyqueryset
. It raises anEmptyResultSet
and returns an empty list for the result. When you combine anEmptyResultSet
querywith_cte
unfortunately,django-cte
does not recognize it, and throws an error instead of returning an empty list.for a quick fix, you can overwrite the
__iter__
method of theCTEQuerySet
, but this is not a proper solution.The text was updated successfully, but these errors were encountered: