#35459: Case.extra is undocumented, untested, and can hide potential issues
-------------------------------------+-------------------------------------
     Reporter:  Baptiste Mispelon    |                    Owner:  Priyank
         Type:                       |  Panchal
  Cleanup/optimization               |                   Status:  assigned
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):

 After looking more at the history, I'm nervous about removing `**extra`
 from `Case` and/or `Subquery`/`Exists` given how close it is to the
 documented pattern for `Func`. In particular, we have an
 [https://docs.djangoproject.com/en/6.0/ref/models/expressions/#writing-
 your-own-query-expressions example] of rewriting `Coalesce` from scratch
 that inherits from `Expression` rather than `Func`, and it follows the
 `Func`-style dynamic provision of `template`. The way
 `Case`/`Subquery`/`Exists` allow dynamic templates feels like dogfooding
 our own example.

 > (Currently, template is pulled from extra:
 template_params.get("template", self.template) in as_sql().) I'm not sure
 if it's useful.

 A [https://github.com/django/django/pull/6302/files#r56357943 similar
 question] was asked at the time, and the answer was, at least for `Func`
 subclasses, it could be useful. I'm worried saying it's useful for `Func`
 subclasses but not `Exists` is a hyperfine distinction. (A `Subquery`
 subclass might also want to specialize the template per backend, but
 accept a generic parameter for all backends in `as_sql`, like `Cast`
 does.)

 Given that, my preference would be to close this ticket via documentation
 and tests, but with improving the example (perhaps using a `CustomExists`
 expression that is factored like `Cast`, e.g. it has vendor-specific
 templates all relying on a single parameter accepted from `as_sql()`).
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35459#comment:18>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019ae579cdd5-ca36c046-eb39-4a69-b1f5-626be1f2c811-000000%40eu-central-1.amazonses.com.

Reply via email to