From e57ce6b15714c3697bec8a911443aca6cf1172d2 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 10 Feb 2007 03:39:56 +0000 Subject: [PATCH] Fixed #2348 -- Improved error reporting when query filter arguments are misspelt. Variation on a patch from Karen Tracey. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4470 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/query.py | 10 ++++++++-- tests/modeltests/lookup/models.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 51fa334e63..2ddcd449cf 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -881,8 +881,14 @@ def lookup_inner(path, lookup_type, value, opts, table, column): new_opts = field.rel.to._meta new_column = new_opts.pk.column join_column = field.column - - raise FieldFound + raise FieldFound + elif path: + # For regular fields, if there are still items on the path, + # an error has been made. We munge "name" so that the error + # properly identifies the cause of the problem. + name += LOOKUP_SEPARATOR + path[0] + else: + raise FieldFound except FieldFound: # Match found, loop has been shortcut. pass diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py index aa903d1a64..8468d396f7 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -206,4 +206,15 @@ DoesNotExist: Article matching query does not exist. >>> Article.objects.exclude(id__in=[]) [, , , , , , , , , ] +# Programming errors are pointed out with nice error messages +>>> Article.objects.filter(pub_date_year='2005').count() +Traceback (most recent call last): + ... +TypeError: Cannot resolve keyword 'pub_date_year' into field + +>>> Article.objects.filter(headline__starts='Article') +Traceback (most recent call last): + ... +TypeError: Cannot resolve keyword 'headline__starts' into field + """}