Re: [Django] #34858: Output field for combined PositiveIntegerField is not properly resolved. (was: Bug in output field handling)

5 views
Skip to first unread message

Django

unread,
Sep 21, 2023, 3:48:41 AM9/21/23
to django-...@googlegroups.com
#34858: Output field for combined PositiveIntegerField is not properly resolved.
-------------------------------------+-------------------------------------
Reporter: Toan Vuong | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Simon Charette, Luke Plant (added)
* type: Uncategorized => Bug
* component: Uncategorized => Database layer (models, ORM)
* stage: Unreviewed => Accepted


Comment:

Thanks for the ticket. This is not strictly related with Oracle, the main
issue is that `output_field` is not properly resolved for a combination of
`PositiveIntegerField`. `Coalesce()` on Oracle checks the `output_field`
of arguments and crashes. We should be able to fix this but prioritize
`PositiveIntegerField`, e.g.
{{{#!diff
diff --git a/django/db/models/expressions.py
b/django/db/models/expressions.py
index 4ea179ecde..54edaa611c 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -512,6 +512,23 @@ class Expression(BaseExpression, Combinable):

_connector_combinations = [
# Numeric operations - operands of same type.
+ {
+ # PositiveIntegerField should take precedence over IntegerField.
+ connector: [
+ (
+ fields.PositiveIntegerField,
+ fields.PositiveIntegerField,
+ fields.PositiveIntegerField,
+ ),
+ ]
+ for connector in (
+ Combinable.ADD,
+ Combinable.MUL,
+ Combinable.DIV,
+ Combinable.MOD,
+ Combinable.POW,
+ )
+ },
{
connector: [
(fields.IntegerField, fields.IntegerField,
fields.IntegerField),

}}}

Would you like to prepare a patch (via GitHub PR)? a regression test is
required.


Regression in 40b8a6174f001a310aa33f7880db0efeeb04d4c4 (#33397).

--
Ticket URL: <https://code.djangoproject.com/ticket/34858#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages