Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit e57ce6b15714c3697bec8a911443aca6cf1172d2 1 parent f0a3f5f
Malcolm Tredinnick authored February 10, 2007
10  django/db/models/query.py
@@ -881,8 +881,14 @@ def lookup_inner(path, lookup_type, value, opts, table, column):
881 881
                 new_opts = field.rel.to._meta
882 882
                 new_column = new_opts.pk.column
883 883
                 join_column = field.column
884  
-
885  
-            raise FieldFound
  884
+                raise FieldFound
  885
+            elif path:
  886
+                # For regular fields, if there are still items on the path,
  887
+                # an error has been made. We munge "name" so that the error
  888
+                # properly identifies the cause of the problem.
  889
+                name += LOOKUP_SEPARATOR + path[0]
  890
+            else:
  891
+                raise FieldFound
886 892
 
887 893
     except FieldFound: # Match found, loop has been shortcut.
888 894
         pass
11  tests/modeltests/lookup/models.py
@@ -206,4 +206,15 @@ def __str__(self):
206 206
 >>> Article.objects.exclude(id__in=[])
207 207
 [<Article: Article with \ backslash>, <Article: Article% with percent sign>, <Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>]
208 208
 
  209
+# Programming errors are pointed out with nice error messages
  210
+>>> Article.objects.filter(pub_date_year='2005').count()
  211
+Traceback (most recent call last):
  212
+    ...
  213
+TypeError: Cannot resolve keyword 'pub_date_year' into field
  214
+
  215
+>>> Article.objects.filter(headline__starts='Article')
  216
+Traceback (most recent call last):
  217
+    ...
  218
+TypeError: Cannot resolve keyword 'headline__starts' into field
  219
+
209 220
 """}

0 notes on commit e57ce6b

Please sign in to comment.
Something went wrong with that request. Please try again.