#34160: Django 4.1 Expression contains mixed types for (Big/Small)IntegerFields.
-------------------------------------+-------------------------------------
     Reporter:  Martin Lehoux        |                    Owner:  Martin
                                     |  Lehoux
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  4.1
  (models, ORM)                      |
     Severity:  Release blocker      |               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 Simon Charette):

 What I believe is happening here is that `F("inventory_count") + Value(1)`
 has its `output_field` resolved to `IntegerField` because it's the common
 base of `inventory_count` (which I assume is a `SmallIntegerField` since
 the models were not provided).

 While `CombinedExpression._resolve_output_field` resolving logic deals
 with subclassing properly `BaseExpression._resolve_output_field`
 
[https://github.com/django/django/blob/2848e5d0ce5cf3c31fe87525536093b21d570f69/django/db/models/expressions.py#L327-L329
 isn't smart enough] to resolve a mix of `IntegerField` subclasses to the
 largest denominator.

 The three ways we could be fixing that would be:
 1. Document this requirement the usage of explicit `output_field` either
 to `Value` [https://docs.djangoproject.com/en/4.1/releases/3.2/ beyond the
 3.2 release notes].
 2. Make `Value._resolve_field` use different kind of `IntegerField`
 subclasses when dealing with smaller/larger values. This could have the
 unintended side effect of surfacing even more errors for mixed type as
 `Value(n < 255)`  would resolve to `SmallIntegerField` so I think this is
 a bad idea.
 3. Actually make `BasExpression._resolve_output_field` smarter with the
 deprecation period it requires.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34160#comment:10>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018481b3bbca-a528cd77-ac7d-4976-bb80-b8e40b8ab4c9-000000%40eu-central-1.amazonses.com.

Reply via email to