#25425: Enforce calling resolve_expression before as_sql on all expressions
-------------------------------------+-------------------------------------
     Reporter:  jarshwah             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by akaariai):

 The way expressions in filter() calls work is that if you do
 `.filter(Greater(F('field'), 3))`, then Greater is resolved to an
 expression, and that expression is added to WhereNode.

 Similarly, if you do `.filter(Q(Greater(F('field'), 3)) &
 Q(Greater(F('other_field'), 4)))`, then the Q is resolved, and this also
 resolves the nested expressions. Finally the resolved expression is added
 to the query's WhereNode.

 Notably you can't do `.filter(WhereNode(Greater(F('field', 3))))`. But
 this is alright, the user facing API is Q-objects, not WhereNode objects.
 Also, you are free to generate an expression that resolves to a WhereNode,
 but WhereNode itself isn't resolvable.

 What we should do is enforce that any expression added to a WhereNode is
 already resolved.

 Now, we could also add a required attribute `resolved` to all compilables.
 Then we could check if that attribute is set in compiler.compile(). Those
 objects that aren't resolvable could set it always to True. I'm not
 convinced this is needed, but I won't object to doing this.

--
Ticket URL: <https://code.djangoproject.com/ticket/25425#comment:3>
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/066.159a490a17b9acb4c99232e2878e6af6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to