#30548: Improve exception message when BaseExpression raises "'Expression 
contains
mixed types. You must set output_field.'"
-------------------------------------+-------------------------------------
               Reporter:  Keryn      |          Owner:  nobody
  Knight                             |
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:  Database   |        Version:  master
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  expressions orm
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 The
 
[https://github.com/django/django/blob/661e6cc2c97d9bcb45198be787409488e1825c90/django/db/models/expressions.py#L290
 source which raises the exception] has enough information to say both what
 types were found, and which of those were unexpected, **and** probably
 have a useful `repr()`

 In the test suite, the unexpected output types encountered seem to be
 `DurationField` and `IntegerField`, so a more thorough message might be
 something like:
 `Expression repr(self) contained mixed types: DateField, DurationField.
 DurationField was unexpected; you must set the output_field= for this
 Expression to either DurationField(), DateField() or ...` (''??? I dunno,
 some concrete explanation of what the output_field has to be/implement if
 you're not going to use any of the builtins'')

 The merit of including the repr is arguable, as the `Expression` may not
 what the user put in (eg: in the test suite it always seems to be a
 `CombinedExpression(lhs, connector, rhs)`) but it gives more of a hint in
 a query which contains multiple expressions (either nested or separate) as
 to which one is actually causing the problem vs just being told "something
 was wrong. Put an output_field= everywhere until it ceases, your guess is
 as good as mine"; at the very least the word Expression could be replaced
 with the class name which is actually raising it.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30548>
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/052.af08044ab376e97c2f55ff8f0dc59c73%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to