From b5f8c81ce18528ecf7cb4605dca864c961da9373 Mon Sep 17 00:00:00 2001 From: Anderson Resende Date: Tue, 5 Jan 2016 23:47:27 -0300 Subject: [PATCH] Fixed #26026 -- Fixed isinstance crash comparing EmptyQuerySet to non-QuerySet. --- django/db/models/query.py | 2 +- tests/basic/tests.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 45c0320254..b1bebcaca0 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 isinstance(instance, QuerySet) and instance.query.is_empty() class EmptyQuerySet(six.with_metaclass(InstanceCheckMeta)): diff --git a/tests/basic/tests.py b/tests/basic/tests.py index c67f78926f..c334a8bfc6 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -367,6 +367,7 @@ class ModelTest(TestCase): with self.assertRaises(TypeError): EmptyQuerySet() self.assertIsInstance(Article.objects.none(), EmptyQuerySet) + self.assertFalse(isinstance('', EmptyQuerySet)) def test_emptyqs_values(self): # test for #15959