#26026: EmptyQuerySet isinstance check broken with not QuerySet datatypes
--------------------------------+--------------------
Reporter: vladimirbright | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------
isinstance check on any instance, that is not QuerySet (actually anything
without .query attribute) and django.db.models.query.EmptyQuerySet throws
AttributeError.
Code to reproduce.
{{{
In [9]: from django.db.models.query import EmptyQuerySet
In [10]: isinstance(1, EmptyQuerySet)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call
last)
<ipython-input-10-79a6a197988a> in <module>()
----> 1 isinstance(1, EmptyQuerySet)
/home/vprokhoda/Envs/ADMIN2/local/lib/python2.7/site-
packages/django/db/models/query.pyc in __instancecheck__(self, instance)
1171 class InstanceCheckMeta(type):
1172 def __instancecheck__(self, instance):
-> 1173 return instance.query.is_empty()
1174
1175
AttributeError: 'int' object has no attribute 'query'
In [11]:
In [11]: import django
In [12]: django.__version__
Out[12]: '1.9'
}}}
Quick and dirty fix is
{{{
(django)vprokhoda@tests$ git diff
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 45c0320..0cc5f94 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1171,7 +1171,7 @@ class QuerySet(object):
class InstanceCheckMeta(type):
def __instancecheck__(self, instance):
- return instance.query.is_empty()
+ return hasattr(instance, 'query') and instance.query.is_empty()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26026>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/057.ac4bf8fb5c0377b8376b79d92d24cb7c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.