summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Wilson <alex.wilson@venmo.com>2015-04-13 18:57:11 -0400
committerTim Graham <timograham@gmail.com>2015-04-14 13:28:53 -0400
commit99d40c6f658ead97f67d331eed9278805c8a4007 (patch)
tree123f99f3a069c440b58b12a9acf0d7242bae4ab1
parent825bb0ab08cec353edcd2b9aea651bfe9392ef97 (diff)
Fixed #24277 -- Added exception when dict used in QuerySet filtering
-rw-r--r--django/db/models/sql/query.py2
-rw-r--r--tests/queries/tests.py4
2 files changed, 6 insertions, 0 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 69178680ee..b514cc4783 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -1121,6 +1121,8 @@ class Query(object):
query. However, if the filter isn't added to the query then the caller
is responsible for unreffing the joins used.
"""
+ if isinstance(filter_expr, dict):
+ raise FieldError("Cannot parse keyword query as dict")
arg, value = filter_expr
if not arg:
raise FieldError("Cannot parse keyword query %r" % arg)
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 82d6d1fe7c..f688d0ed90 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -440,6 +440,10 @@ class Queries1Tests(BaseQuerysetTest):
['<Item: four>']
)
+ def test_error_raised_on_filter_with_dictionary(self):
+ with self.assertRaisesMessage(FieldError, 'Cannot parse keyword query as dict'):
+ Note.objects.filter({'note': 'n1', 'misc': 'foo'})
+
def test_tickets_2076_7256(self):
# Ordering on related tables should be possible, even if the table is
# not otherwise involved.