diff options
| author | Michael Blatherwick <michael.blatherwick@exeter.oxon.org> | 2015-03-22 13:04:53 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-03-23 10:31:57 -0400 |
| commit | 00e667728ba3ef1b5cb3de0e11c7648b89315a91 (patch) | |
| tree | d2252c0732be5c81e337ccd5fb49bfc59fa80e3c | |
| parent | a4a58811b9729ed1ab2417d72e5d07ebb1a30886 (diff) | |
Fixed #23697 -- Improved ForeignObject.get_lookup_constraint() error message.
| -rw-r--r-- | django/db/models/fields/related.py | 7 | ||||
| -rw-r--r-- | tests/queries/tests.py | 9 |
2 files changed, 15 insertions, 1 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 45c9b15081..0ca4e59633 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -1766,7 +1766,12 @@ class ForeignObject(RelatedField): root_constraint = constraint_class() assert len(targets) == len(sources) if len(lookups) > 1: - raise exceptions.FieldError('Relation fields do not support nested lookups') + raise exceptions.FieldError( + "Cannot resolve keyword %r into field. Choices are: %s" % ( + lookups[0], + ", ".join(f.name for f in self.model._meta.get_fields()), + ) + ) lookup_type = lookups[0] def get_normalized_value(value): diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 0f86a0f066..9c521c1c03 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -1164,6 +1164,15 @@ class Queries1Tests(BaseQuerysetTest): ['<Author: a1>', '<Author: a2>', '<Author: a3>', '<Author: a4>'] ) + def test_lookup_constraint_fielderror(self): + msg = ( + "Cannot resolve keyword 'unknown_field' into field. Choices are: " + "annotation, category, category_id, children, id, item, " + "managedmodel, name, parent, parent_id" + ) + with self.assertRaisesMessage(FieldError, msg): + Tag.objects.filter(unknown_field__name='generic') + class Queries2Tests(TestCase): @classmethod |
