#31783: Filtering on a field named `negate` raises a TypeError
-------------------------------------+-------------------------------------
Reporter: Aaron Kirkbride | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):
Aaron, would you be interested in submitting a PR with the changes below
plus a regression test in `tests/query/tests.py`?
{{{#!diff
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 07d6ffd4ca..d655ede8d9 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -204,7 +204,7 @@ class QuerySet:
def query(self):
if self._deferred_filter:
negate, args, kwargs = self._deferred_filter
- self._filter_or_exclude_inplace(negate, *args, **kwargs)
+ self._filter_or_exclude_inplace(negate, args, kwargs)
self._deferred_filter = None
return self._query
@@ -939,7 +939,7 @@ class QuerySet:
set.
"""
self._not_support_combined_queries('filter')
- return self._filter_or_exclude(False, *args, **kwargs)
+ return self._filter_or_exclude(False, args, kwargs)
def exclude(self, *args, **kwargs):
"""
@@ -947,9 +947,9 @@ class QuerySet:
set.
"""
self._not_support_combined_queries('exclude')
- return self._filter_or_exclude(True, *args, **kwargs)
+ return self._filter_or_exclude(True, args, kwargs)
- def _filter_or_exclude(self, negate, *args, **kwargs):
+ def _filter_or_exclude(self, negate, args, kwargs):
if args or kwargs:
assert not self.query.is_sliced, \
"Cannot filter a query once a slice has been taken."
@@ -959,10 +959,10 @@ class QuerySet:
self._defer_next_filter = False
clone._deferred_filter = negate, args, kwargs
else:
- clone._filter_or_exclude_inplace(negate, *args, **kwargs)
+ clone._filter_or_exclude_inplace(negate, args, kwargs)
return clone
- def _filter_or_exclude_inplace(self, negate, *args, **kwargs):
+ def _filter_or_exclude_inplace(self, negate, args, kwargs):
if negate:
self._query.add_q(~Q(*args, **kwargs))
else:
@@ -983,7 +983,7 @@ class QuerySet:
clone.query.add_q(filter_obj)
return clone
else:
- return self._filter_or_exclude(False, **filter_obj)
+ return self._filter_or_exclude(False, args=(),
kwargs=filter_obj)
def _combinator_query(self, combinator, *other_qs, all=False):
# Clone the query to inherit the select list and everything
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31783#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.c95d3c397221a06168003e2c4960eda1%40djangoproject.com.