diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-28 21:03:24 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-03-28 21:03:48 +0200 |
| commit | f12dc36754bf24aeb3da79f18fc3c9a3ae1089e0 (patch) | |
| tree | 83e2fcef4446e02d14939acd5f9c0da1cbb4c94b /tests | |
| parent | be6a309b1d749c47821dfdc5add6576f2c61cda0 (diff) | |
[4.2.x] Fixed #34443 -- Fixed filtering by transforms on reverse relations.
Regression in ce6230aa976e8d963226a3956b45a8919215dbd8.
Backport of 996c802229b93fe83c39842e56c6b8668464deaf from main
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/lookup/tests.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py index 89fd582a53..503bae18fc 100644 --- a/tests/lookup/tests.py +++ b/tests/lookup/tests.py @@ -19,7 +19,7 @@ from django.db.models import ( Value, When, ) -from django.db.models.functions import Cast, Length, Substr +from django.db.models.functions import Abs, Cast, Length, Substr from django.db.models.lookups import ( Exact, GreaterThan, @@ -809,6 +809,31 @@ class LookupTests(TestCase): with self.assertRaisesMessage(FieldError, msg): Tag.objects.filter(articles__foo="bar") + def test_unsupported_lookup_reverse_foreign_key(self): + msg = ( + "Unsupported lookup 'title' for ManyToOneRel or join on the field not " + "permitted." + ) + with self.assertRaisesMessage(FieldError, msg): + Author.objects.filter(article__title="Article 1") + + def test_unsupported_lookup_reverse_foreign_key_custom_lookups(self): + msg = ( + "Unsupported lookup 'abspl' for ManyToOneRel or join on the field not " + "permitted, perhaps you meant abspk?" + ) + fk_field = Article._meta.get_field("author") + with self.assertRaisesMessage(FieldError, msg): + with register_lookup(fk_field, Abs, lookup_name="abspk"): + Author.objects.filter(article__abspl=2) + + def test_filter_by_reverse_related_field_transform(self): + fk_field = Article._meta.get_field("author") + with register_lookup(fk_field, Abs): + self.assertSequenceEqual( + Author.objects.filter(article__abs=self.a1.pk), [self.au1] + ) + def test_regex(self): # Create some articles with a bit more interesting headlines for # testing field lookups. |
