Changes between Version 1 and Version 2 of Ticket #34160, comment 10
- Timestamp:
- Nov 16, 2022, 1:09:53 PM (2 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #34160, comment 10
v1 v2 1 1 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) and `Value(1)`. 2 2 3 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. 3 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. By smart I mean that there isn't a proper way do this at such a low level for all subclasses of `BaseExpression` hence [https://github.com/django/django/blob/2848e5d0ce5cf3c31fe87525536093b21d570f69/django/db/models/expressions.py#L327-L329 why it's considered a bad idea to event try doing so]. 4 4 5 5 The three ways we could be fixing that would be: