Fixed #26026 -- Fixed isinstance crash comparing EmptyQuerySet to non-QuerySet.
This commit is contained in:
parent
b643386668
commit
b5f8c81ce1
|
@ -1171,7 +1171,7 @@ class QuerySet(object):
|
||||||
|
|
||||||
class InstanceCheckMeta(type):
|
class InstanceCheckMeta(type):
|
||||||
def __instancecheck__(self, instance):
|
def __instancecheck__(self, instance):
|
||||||
return instance.query.is_empty()
|
return isinstance(instance, QuerySet) and instance.query.is_empty()
|
||||||
|
|
||||||
|
|
||||||
class EmptyQuerySet(six.with_metaclass(InstanceCheckMeta)):
|
class EmptyQuerySet(six.with_metaclass(InstanceCheckMeta)):
|
||||||
|
|
|
@ -367,6 +367,7 @@ class ModelTest(TestCase):
|
||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
EmptyQuerySet()
|
EmptyQuerySet()
|
||||||
self.assertIsInstance(Article.objects.none(), EmptyQuerySet)
|
self.assertIsInstance(Article.objects.none(), EmptyQuerySet)
|
||||||
|
self.assertFalse(isinstance('', EmptyQuerySet))
|
||||||
|
|
||||||
def test_emptyqs_values(self):
|
def test_emptyqs_values(self):
|
||||||
# test for #15959
|
# test for #15959
|
||||||
|
|
Loading…
Reference in New Issue