#25258: ExpressionWrapper documentation should be expanded
-------------------------------+--------------------
Reporter: tarkatronic | Owner: nobody
Type: Bug | Status: new
Component: Documentation | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Currently, ExpressionWrapper has very limited documentation and is only
mentioned for use specifically
[[https://docs.djangoproject.com/en/1.8/ref/models/expressions/#using-f
-with-annotations|in conjunction with F()]].
I ran into a case, using what seems a fairly simple annotation on the
surface, where I needed to use an ExpressionWrapper, but this was not at
all clear from either the error message, any bug reports, or the
documentation.
The following:
{{{
#!python
Category.objects.annotate(
has_children=(
Q(children__merchants__isnull=False) |
Q(children__children__merchants__isnull=False)
)
)
}}}
was producing the error:
{{{
AttributeError: 'WhereNode' object has no attribute 'output_field'
}}}
What I ultimately needed was:
{{{
#!python
Category.objects.annotate(
has_children=ExpressionWrapper(
Q(children__merchants__isnull=False) |
Q(children__children__merchants__isnull=False),
output_field=BooleanField()
)
)
}}}
However, I only stumbled upon this solution completely by accident and on
a hunch.
I think that the documentation for ExpressionWrapper() should be expanded
to cover a more broad use case, and perhaps a more clear error message
could be provided in cases such as the one I encountered.
--
Ticket URL: <https://code.djangoproject.com/ticket/25258>
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/054.cc9080158432b487d88372e47a7b4a00%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.