diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2015-05-19 14:49:00 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-05-20 09:41:42 -0400 |
| commit | db656609289b9eaf4661eb73f9318b7c66540301 (patch) | |
| tree | 01f4dd3ee9c9e6def0bbf1791533e5d30947ed82 /django/db/models/sql | |
| parent | 63d60dfe29a73a6b860a69835c04f727861ff562 (diff) | |
[1.8.x] Fixed #24705 -- Fixed negated Q objects in expressions.
Avoided split_exclude() for Q when used as an expression.
Backport of bc87061a3c7c8d6b4d2469f35cc78683c6cff647 from master
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 387b91a60b..6f883031ef 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1112,7 +1112,7 @@ class Query(object): (name, lhs.output_field.__class__.__name__)) def build_filter(self, filter_expr, branch_negated=False, current_negated=False, - can_reuse=None, connector=AND, allow_joins=True): + can_reuse=None, connector=AND, allow_joins=True, split_subq=True): """ Builds a WhereNode for a single filter clause, but doesn't add it to this Query. Query.add_q() will then add this filter to the where @@ -1161,7 +1161,7 @@ class Query(object): opts = self.get_meta() alias = self.get_initial_alias() - allow_many = not branch_negated + allow_many = not branch_negated or not split_subq try: field, sources, opts, join_list, path = self.setup_joins( @@ -1309,7 +1309,7 @@ class Query(object): self.demote_joins(existing_inner) def _add_q(self, q_object, used_aliases, branch_negated=False, - current_negated=False, allow_joins=True): + current_negated=False, allow_joins=True, split_subq=True): """ Adds a Q-object to the current filter. """ @@ -1323,12 +1323,14 @@ class Query(object): if isinstance(child, Node): child_clause, needed_inner = self._add_q( child, used_aliases, branch_negated, - current_negated, allow_joins) + current_negated, allow_joins, split_subq) joinpromoter.add_votes(needed_inner) else: child_clause, needed_inner = self.build_filter( child, can_reuse=used_aliases, branch_negated=branch_negated, - current_negated=current_negated, connector=connector, allow_joins=allow_joins) + current_negated=current_negated, connector=connector, + allow_joins=allow_joins, split_subq=split_subq, + ) joinpromoter.add_votes(needed_inner) target_clause.add(child_clause, connector) needed_inner = joinpromoter.update_join_types(self) |
