#24705: Exception when negating Q object in annotate
----------------------------------------------+--------------------
Reporter: karyon | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
any of the following
{{{
UserProfile.objects.annotate(is_member=ExpressionWrapper(~Q(groups__name="Group
name"), output_field=BooleanField()))
UserProfile.objects.annotate(is_member=Case(When(~models.Q(groups__name='group
name'), then=Value(False)), default=Value(True),
output_field=models.BooleanField()))
UserProfile.objects.annotate(is_member=Case(When(~Q(groups__name="Group
name"), then=Value(False)), default=Value(True),
output_field=BooleanField()))
}}}
gives the following exception:
{{{
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/django/db/models/query.py",
line 794, in annotate
obj.query.add_annotation(annotation, alias, is_summary=False)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/sql/query.py", line 977, in add_annotation
summarize=is_summary)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/expressions.py", line 779, in resolve_expression
c.cases[pos] = case.resolve_expression(query, allow_joins, reuse,
summarize, for_save)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/expressions.py", line 713, in resolve_expression
c.condition = c.condition.resolve_expression(query, allow_joins,
reuse, summarize, False)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/query_utils.py", line 88, in resolve_expression
clause, _ = query._add_q(self, reuse, allow_joins=allow_joins)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/sql/query.py", line 1328, in _add_q
current_negated=current_negated, connector=connector,
allow_joins=allow_joins)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/sql/query.py", line 1177, in build_filter
can_reuse, e.names_with_path)
File "/usr/local/lib/python3.4/dist-
packages/django/db/models/sql/query.py", line 1570, in split_exclude
if alias in can_reuse:
TypeError: argument of type 'NoneType' is not iterable
}}}
removing the ~ "fixes" this.
see https://github.com/fsr-itse/EvaP for full code (a custom UserProfile
is in evaluation.models), but it looks like this also happens with the
default User model.
--
Ticket URL: <https://code.djangoproject.com/ticket/24705>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.37db201b76b070167dad7587dac8d072%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.