Author: mtredinnick
Date: 2007-02-09 21:39:56 -0600 (Fri, 09 Feb 2007)
New Revision: 4470
Modified:
django/trunk/django/db/models/query.py
django/trunk/tests/modeltests/lookup/models.py
Log:
Fixed #2348 -- Improved error reporting when query filter arguments are
misspelt. Variation on a patch from Karen Tracey.
Modified: django/trunk/django/db/models/query.py
===================================================================
--- django/trunk/django/db/models/query.py 2007-02-10 03:39:14 UTC (rev
4469)
+++ django/trunk/django/db/models/query.py 2007-02-10 03:39:56 UTC (rev
4470)
@@ -881,9 +881,15 @@
new_opts = field.rel.to._meta
new_column = new_opts.pk.column
join_column = field.column
+ 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
- raise FieldFound
-
except FieldFound: # Match found, loop has been shortcut.
pass
else: # No match found.
Modified: django/trunk/tests/modeltests/lookup/models.py
===================================================================
--- django/trunk/tests/modeltests/lookup/models.py 2007-02-10 03:39:14 UTC
(rev 4469)
+++ django/trunk/tests/modeltests/lookup/models.py 2007-02-10 03:39:56 UTC
(rev 4470)
@@ -206,4 +206,15 @@
>>> Article.objects.exclude(id__in=[])
[<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>]
+# 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
+
"""}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---