﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25258	ExpressionWrapper documentation should be expanded	Joey Wilhelm	nobody	"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."	Cleanup/optimization	closed	Documentation	1.8	Normal	duplicate			Accepted	0	0	0	0	0	0
