diff options
| author | Abhinav Patil <apatil.cs@gmail.com> | 2018-09-29 03:22:27 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-10-01 19:03:10 -0400 |
| commit | bf01994a5ccc07cbe4b011b53b644eba04da052e (patch) | |
| tree | 85a1d63bdfba5292d274c568639162cabdc495c2 /django/db/models/sql/query.py | |
| parent | f83a689f617d119a2bed23032919cea98c424c58 (diff) | |
Fixed #29804 -- Added 'did you mean' suggestions for unsupported lookup error.
Diffstat (limited to 'django/db/models/sql/query.py')
| -rw-r--r-- | django/db/models/sql/query.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index beb57f8ecd..7c46c7a237 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -6,6 +6,7 @@ themselves do not have to (and could be backed by things other than SQL databases). The abstraction barrier only works one way: this module has to know all about the internals of models in order to get the information it needs. """ +import difflib import functools from collections import Counter, OrderedDict, namedtuple from collections.abc import Iterator, Mapping @@ -1140,10 +1141,16 @@ class Query: if transform_class: return transform_class(lhs) else: + output_field = lhs.output_field.__class__ + suggested_lookups = difflib.get_close_matches(name, output_field.get_lookups()) + if suggested_lookups: + suggestion = ', perhaps you meant %s?' % ' or '.join(suggested_lookups) + else: + suggestion = '.' raise FieldError( "Unsupported lookup '%s' for %s or join on the field not " - "permitted." % - (name, lhs.output_field.__class__.__name__)) + "permitted%s" % (name, output_field.__name__, suggestion) + ) def build_filter(self, filter_expr, branch_negated=False, current_negated=False, can_reuse=None, allow_joins=True, split_subq=True, |
