summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-28 19:18:48 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-28 19:19:30 +0200
commitbe6a309b1d749c47821dfdc5add6576f2c61cda0 (patch)
tree78aa7798b632e97672f577973fb062d334a7ea16 /tests
parent99ba5b43f094a0354afc2b2b72b7280953b0b971 (diff)
[4.2.x] Refs #29799 -- Added field instance lookups to suggestions in FieldErrors.
Bug in cd1afd553f9c175ebccfc0f50e72b43b9604bd97. Backport of 3afdc9e9b47d5bdd1bd653633b4cb2357478ade5 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/lookup/tests.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index 53eb76d174..89fd582a53 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, Substr
+from django.db.models.functions import Cast, Length, Substr
from django.db.models.lookups import (
Exact,
GreaterThan,
@@ -29,7 +29,7 @@ from django.db.models.lookups import (
LessThanOrEqual,
)
from django.test import TestCase, skipUnlessDBFeature
-from django.test.utils import isolate_apps
+from django.test.utils import isolate_apps, register_lookup
from .models import (
Article,
@@ -784,6 +784,16 @@ class LookupTests(TestCase):
):
Article.objects.filter(pub_date__gobbledygook="blahblah")
+ def test_unsupported_lookups_custom_lookups(self):
+ slug_field = Article._meta.get_field("slug")
+ msg = (
+ "Unsupported lookup 'lengtp' for SlugField or join on the field not "
+ "permitted, perhaps you meant length?"
+ )
+ with self.assertRaisesMessage(FieldError, msg):
+ with register_lookup(slug_field, Length):
+ Article.objects.filter(slug__lengtp=20)
+
def test_relation_nested_lookup_error(self):
# An invalid nested lookup on a related field raises a useful error.
msg = (