Reputation: 1982
Is Django queryset
evaluated in below cases? If no, then why?
if queryset is None:
pass
from django.db.models.query import QuerySet
if isinstance(queryset, QuerySet):
pass
Is it because in both the cases python performs object reference comparison, which does not lead to a query?
Upvotes: 0
Views: 332
Reputation: 77912
As documented, a queryset is evaluated when you try to access its values - by iterating over it (directly or indirectly), subscribing/slicing it, printing it (actually: calling repr()
on it) or testing it's truth value.
is
is the identity operator, it compares objects identifiers, so it doesn't evaluate the queryset.
isinstance
checks the object's class (and the class mro), so it doesn't evaluate the queryset either.
Upvotes: 3