diff options
author | Tim Graham <timograham@gmail.com> | 2017-10-16 11:10:21 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2017-10-16 13:56:38 -0400 |
commit | 1b73ccc4bf78af905f72f4658cf463f38ebf7b97 (patch) | |
tree | 5fb10a733542297ab5adbe52a04ca3ffc5f1abaa /tests/lookup | |
parent | 61a6245dc5c9ad8423dcceb47fdeff167c838542 (diff) | |
download | django-1b73ccc4bf78af905f72f4658cf463f38ebf7b97.tar.gz |
Fixed #28497 -- Restored the ability to use sliced QuerySets with __exact.
Regression in ec50937bcbe160e658ef881021402e156beb0eaf.
Thanks Simon Charette for review.
Diffstat (limited to 'tests/lookup')
-rw-r--r-- | tests/lookup/tests.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py index 7b08c778df..0161782dbe 100644 --- a/tests/lookup/tests.py +++ b/tests/lookup/tests.py @@ -848,6 +848,28 @@ class LookupTests(TestCase): self.assertTrue(Season.objects.filter(nulled_text_field__nulled__exact=None)) self.assertTrue(Season.objects.filter(nulled_text_field__nulled=None)) + def test_exact_sliced_queryset_limit_one(self): + self.assertCountEqual( + Article.objects.filter(author=Author.objects.all()[:1]), + [self.a1, self.a2, self.a3, self.a4] + ) + + def test_exact_sliced_queryset_limit_one_offset(self): + self.assertCountEqual( + Article.objects.filter(author=Author.objects.all()[1:2]), + [self.a5, self.a6, self.a7] + ) + + def test_exact_sliced_queryset_not_limited_to_one(self): + msg = ( + 'The QuerySet value for an exact lookup must be limited to one ' + 'result using slicing.' + ) + with self.assertRaisesMessage(ValueError, msg): + list(Article.objects.filter(author=Author.objects.all()[:2])) + with self.assertRaisesMessage(ValueError, msg): + list(Article.objects.filter(author=Author.objects.all()[1:])) + def test_custom_field_none_rhs(self): """ __exact=value is transformed to __isnull=True if Field.get_prep_value() |