[Django] #35257: db.models.expressions _connector_combinations for Numeric with NULL returns only FloatField instead of (IntegerField, DecimalField, FloatField)

14 views
Skip to first unread message

Django

unread,
Feb 27, 2024, 9:39:34 AM2/27/24
to django-...@googlegroups.com
#35257: db.models.expressions _connector_combinations for Numeric with NULL returns
only FloatField instead of (IntegerField, DecimalField, FloatField)
-------------------------------------+-------------------------------------
Reporter: Sharon | Owner: nobody
Woo |
Type: Bug | Status: assigned
Component: Database | Version: 5.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Discovered via writing tests for this related ticket with a LOT of help
from David Sanders -- https://code.djangoproject.com/ticket/35235.

In
https://github.com/django/django/blob/ef2434f8508551fee183079ab471b1dc325c7acb/django/db/models/expressions.py#L599-L613
via https://github.com/django/django/pull/15271,

the dictionary comprehension below

{{{
{
connector: [
(field_type, NoneType, field_type),
(NoneType, field_type, field_type),
]
for connector in (
Combinable.ADD,
Combinable.SUB,
Combinable.MUL,
Combinable.DIV,
Combinable.MOD,
Combinable.POW,
)
for field_type in (fields.IntegerField, fields.DecimalField,
fields.FloatField)
},
}}}

returns

{{{
Combinable.ADD: [(fields.FloatField, NoneType, fields.FloatField),
(NoneType, fields.FloatField, fields.FloatField),],
Combinable.SUB: [(fields.FloatField, NoneType, fields.FloatField),
(NoneType, fields.FloatField, fields.FloatField),],
...
}}}

instead of the expected

{{{
Combinable.ADD: [(fields.IntegerField, NoneType, fields.IntegerField),
(NoneType, fields.IntegerField, fields.IntegerField),
(fields.DecimalField, NoneType, fields.DecimalField),
(NoneType, fields.DecimalField, fields.DecimalField),
(fields.FloatField, NoneType, fields.FloatField),
(NoneType, fields.FloatField, fields.FloatField),
],
...
}}}

This leads to only FloatField throwing FieldError with
`_output_field_or_none` when fields are combined with NULL.

Examples you can run right now:

{{{
original_dict_comp = {
connector: (
(field_type, None, field_type),
(None, field_type, field_type),
)
for connector in (
'ADD', 'SUB', 'MUL', 'DIV', 'MOD', 'POW',
)
for field_type in ('IntegerField', 'DecimalField', 'FloatField')
}

# there are a few ways to write this one
fixed_dict_comp = {
key: [
(field_type, None, field_type)
for field_type in ['IntegerField', 'DecimalField', 'FloatField']
] + [
(None, field_type, field_type)
for field_type in ['IntegerField', 'DecimalField', 'FloatField']
]
for key in ['ADD', 'SUB', 'MUL', 'DIV', 'MOD', 'POW']
}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35257>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 27, 2024, 9:41:12 AM2/27/24
to django-...@googlegroups.com
#35257: db.models.expressions _connector_combinations for Numeric with NULL returns
only FloatField instead of (IntegerField, DecimalField, FloatField)
-------------------------------------+-------------------------------------
Reporter: Sharon Woo | Owner: nobody
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(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 David Sanders):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/35257#comment:1>

Django

unread,
Feb 27, 2024, 9:41:49 AM2/27/24
to django-...@googlegroups.com
#35257: db.models.expressions _connector_combinations for Numeric with NULL returns
only FloatField instead of (IntegerField, DecimalField, FloatField)
-------------------------------------+-------------------------------------
Reporter: Sharon Woo | Owner: Sharon
| Woo
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(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 Sharon Woo):

* owner: nobody => Sharon Woo

--
Ticket URL: <https://code.djangoproject.com/ticket/35257#comment:2>

Django

unread,
Feb 28, 2024, 12:39:49 PM2/28/24
to django-...@googlegroups.com
#35257: db.models.expressions _connector_combinations for Numeric with NULL returns
only FloatField instead of (IntegerField, DecimalField, FloatField)
-------------------------------------+-------------------------------------
Reporter: Sharon Woo | Owner: Sharon
| Woo
Type: Bug | 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: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sharon Woo):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/17916 PR] in progress, comments
very welcome.
--
Ticket URL: <https://code.djangoproject.com/ticket/35257#comment:3>

Django

unread,
Mar 8, 2024, 12:30:59 AM3/8/24
to django-...@googlegroups.com
#35257: db.models.expressions _connector_combinations for Numeric with NULL returns
only FloatField instead of (IntegerField, DecimalField, FloatField)
-------------------------------------+-------------------------------------
Reporter: Sharon Woo | Owner: Sharon
| Woo
Type: Bug | 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
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35257#comment:4>

Django

unread,
Mar 21, 2024, 4:16:51 AM3/21/24
to django-...@googlegroups.com
#35257: db.models.expressions _connector_combinations for Numeric with NULL returns
only FloatField instead of (IntegerField, DecimalField, FloatField)
-------------------------------------+-------------------------------------
Reporter: Sharon Woo | Owner: Sharon
| Woo
Type: Bug | Status: assigned
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35257#comment:5>

Django

unread,
Mar 21, 2024, 5:50:12 AM3/21/24
to django-...@googlegroups.com
#35257: db.models.expressions _connector_combinations for Numeric with NULL returns
only FloatField instead of (IntegerField, DecimalField, FloatField)
-------------------------------------+-------------------------------------
Reporter: Sharon Woo | Owner: Sharon
| Woo
Type: Bug | Status: closed
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"6a37e9bfae42eb180a8c978a3ade5b41c97c26b1" 6a37e9b]:
{{{#!CommitTicketReference repository=""
revision="6a37e9bfae42eb180a8c978a3ade5b41c97c26b1"
Fixed #35257 -- Corrected resolving output_field for
IntegerField/DecimalField with NULL.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35257#comment:6>
Reply all
Reply to author
Forward
0 new messages