mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Refs #29799 -- Added field instance lookups to suggestions in FieldErrors.
Bug in cd1afd553f.
			
			
This commit is contained in:
		| @@ -1305,7 +1305,7 @@ class Query(BaseExpression): | |||||||
|         else: |         else: | ||||||
|             output_field = lhs.output_field.__class__ |             output_field = lhs.output_field.__class__ | ||||||
|             suggested_lookups = difflib.get_close_matches( |             suggested_lookups = difflib.get_close_matches( | ||||||
|                 name, output_field.get_lookups() |                 name, lhs.output_field.get_lookups() | ||||||
|             ) |             ) | ||||||
|             if suggested_lookups: |             if suggested_lookups: | ||||||
|                 suggestion = ", perhaps you meant %s?" % " or ".join(suggested_lookups) |                 suggestion = ", perhaps you meant %s?" % " or ".join(suggested_lookups) | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ from django.db.models import ( | |||||||
|     Value, |     Value, | ||||||
|     When, |     When, | ||||||
| ) | ) | ||||||
| from django.db.models.functions import Cast, Substr | from django.db.models.functions import Cast, Length, Substr | ||||||
| from django.db.models.lookups import ( | from django.db.models.lookups import ( | ||||||
|     Exact, |     Exact, | ||||||
|     GreaterThan, |     GreaterThan, | ||||||
| @@ -29,7 +29,7 @@ from django.db.models.lookups import ( | |||||||
|     LessThanOrEqual, |     LessThanOrEqual, | ||||||
| ) | ) | ||||||
| from django.test import TestCase, skipUnlessDBFeature | 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 ( | from .models import ( | ||||||
|     Article, |     Article, | ||||||
| @@ -813,6 +813,16 @@ class LookupTests(TestCase): | |||||||
|         ): |         ): | ||||||
|             Article.objects.filter(pub_date__gobbledygook="blahblah") |             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): |     def test_relation_nested_lookup_error(self): | ||||||
|         # An invalid nested lookup on a related field raises a useful error. |         # An invalid nested lookup on a related field raises a useful error. | ||||||
|         msg = ( |         msg = ( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user