diff options
| author | Thomas Chaumeny <t.chaumeny@gmail.com> | 2014-09-07 00:13:46 +0200 |
|---|---|---|
| committer | Loic Bistuer <loic.bistuer@gmail.com> | 2014-09-19 01:01:31 +0700 |
| commit | e008a10c2ffef7d64100bcbe83ef2c5f4b1b2168 (patch) | |
| tree | 8a00a1180ce3ee8026634a68fb585e166ea5c30a /django/db/models/sql | |
| parent | abc11b0a33fd823ad341ab2cc113c73545eb61e6 (diff) | |
Fixed #23443 -- Corrected erroneous FieldError message.
Thanks Tim Graham for the review.
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 7524a3582d..d8c711d18f 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1370,9 +1370,13 @@ class Query(object): try: field, model, direct, m2m = opts.get_field_by_name(name) except FieldDoesNotExist: - # We didn't found the current field, so move position back + # We didn't find the current field, so move position back # one step. pos -= 1 + if pos == -1 or fail_on_missing: + available = opts.get_all_field_names() + list(self.aggregate_select) + raise FieldError("Cannot resolve keyword %r into field. " + "Choices are: %s" % (name, ", ".join(available))) break # Check if we need any joins for concrete inheritance cases (the # field lives in parent, but we are currently in one of its @@ -1412,16 +1416,13 @@ class Query(object): # Local non-relational field. final_field = field targets = (field,) + if fail_on_missing and pos + 1 != len(names): + raise FieldError( + "Cannot resolve keyword %r into field. Join on '%s'" + " not permitted." % (names[pos + 1], name)) break - if pos == -1 or (fail_on_missing and pos + 1 != len(names)): - self.raise_field_error(opts, name) return path, final_field, targets, names[pos + 1:] - def raise_field_error(self, opts, name): - available = opts.get_all_field_names() + list(self.aggregate_select) - raise FieldError("Cannot resolve keyword %r into field. " - "Choices are: %s" % (name, ", ".join(available))) - def setup_joins(self, names, opts, alias, can_reuse=None, allow_many=True): """ Compute the necessary table joins for the passage through the fields |
