#32548: Support passing conditional expressions to Q().
-------------------------------------+-------------------------------------
     Reporter:  jonathan-golorry     |                    Owner:  jonathan-
         Type:                       |  golorry
  Cleanup/optimization               |                   Status:  assigned
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  Q objects,           |             Triage Stage:  Accepted
  deconstruct                        |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  1                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak):

 > Django already passes conditional expressions to Q objects internally.
 https://github.com/django/django/blob/main/django/db/models/expressions.py#L113
 >
 > Tested here
 https://github.com/django/django/blob/main/tests/expressions/tests.py#L827

 These are example of combining conditional expressions. Again,
 initializing `Q` objects with conditional expressions is undocumented and
 untested.

 > That test is only succeeding because `Q(...) | Q(Q())` is treated
 differently from `Q(...) | Q()`.

 I'm not sure how it's related with the ticket 🤔

 > As for the form of `.deconstruct()`, is there any reason for keeping the
 special case? It's:
 >
 > 1. Inconsistent: `Q(x=1).deconstruct()` vs `Q(x=1, y=2).deconstruct()`

 First is a single condition without a connector.

 > 2. Fragile: Unsupported inputs like `Q(False)` sometimes (but not
 always!) lead to "not subscriptable" errors.
 > 3. Incorrect: `Q(("x", 1)).deconstruct()` incorrectly puts the condition
 in  kwargs instead of args.

 I wouldn't say that is incorrect `Q(('x', 1))` is equivalent to the
 `Q(x=1)` so I don't see anything wrong with this behavior.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32548#comment:5>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/074.32e143d9c227c539100be5321ac1fb75%40djangoproject.com.

Reply via email to