#25258: ExpressionWrapper documentation should be expanded
--------------------------------------+------------------------------------
     Reporter:  tarkatronic           |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Documentation         |                  Version:  1.8
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by jarshwah):

 `Q()` objects aren't actually expressions, but they are made from similar
 base types, and support parts of the expression API by virtue of being
 required by `Case Expressions`
 https://docs.djangoproject.com/en/1.8/ref/models/conditional-expressions/.

 I've seen quite a few cases of people using `Q()` objects as expressions
 lately, when they really should be using Conditional Expressions instead.

 So, I agree that something here needs to be fixed or documented. But
 `ExpressionWrapper` really is only meant to be used to wrap existing
 expressions, so I'm not too keen on documenting ExpressionWrapper further
 at this point.

 I guess we could define the output_field of Q() objects as always
 returning a BooleanField but, again, they aren't exactly Expressions
 themselves although they are close.

 I think the better options here are:

 1) Make Q() objects actual expressions (by implementing the full
 expression API on them). Not sure if Q() expressions will always work as
 annotations though, conditional expressions had some extra work to do to
 be compliant cross database.

 2) Highlight that Conditional Expressions should be used in the
 documentation and error messages where Q() objects are mentioned. Erroring
 early on direct Q() usage in annotations and guiding the user to Case/When
 is what I imagine here.

 I'm open to further suggestions.

--
Ticket URL: <https://code.djangoproject.com/ticket/25258#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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.99fad353f71c07a79a8edb0632420398%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to