From b679a3cdb119b375f32c3d89b967f9cf6e7fa2f5 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 14 Oct 2016 08:48:50 -0400 Subject: [PATCH] Tested QuerySet compatibility check. cdfdcf4b70bebfc68871df885387790c6afbc23c missed this test. --- django/db/models/sql/query.py | 2 +- tests/queries/tests.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 5f3db65e8e..aeb722ba50 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1059,7 +1059,7 @@ class Query(object): if not value.is_compatible_query_object_type(opts, field): raise ValueError( 'Cannot use QuerySet for "%s": Use a QuerySet for "%s".' % - (value.model._meta.model_name, opts.object_name) + (value.model._meta.object_name, opts.object_name) ) elif hasattr(value, '_meta'): self.check_query_object_type(value, opts, field) diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 9e65b1a412..5b1f9f6ad1 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -2969,6 +2969,11 @@ class QuerySetExceptionTests(TestCase): with self.assertRaisesMessage(FieldError, msg): list(Article.objects.order_by('*')) + def test_invalid_queryset_model(self): + msg = 'Cannot use QuerySet for "Article": Use a QuerySet for "ExtraInfo".' + with self.assertRaisesMessage(ValueError, msg): + list(Author.objects.filter(extra=Article.objects.all())) + class NullJoinPromotionOrTest(TestCase): @classmethod