Opened 2 years ago

Closed 19 months ago

#33464 closed Cleanup/optimization (fixed)

Resolve output_field when combining numeric expressions with MOD operator.

Reported by: gsinghkular Owned by: David Wobrock
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: David Wobrock Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When writing a Django expression for a query that does MOD, if the types of the query are different (Decimal and Integer), it doesn't resolve the result to a Decimal type, like it does for other mathematical operators.

Change History (9)

comment:1 by Mariusz Felisiak, 2 years ago

Resolution: duplicate
Status: newclosed
Type: UncategorizedCleanup/optimization

Duplicate of #33397.

comment:2 by Luke Plant, 2 years ago

Resolution: duplicate
Status: closednew

I'm pretty sure the changes committed as part of #33397, while closely related, doesn't actually address this case. I think it's best to handle this as a separate ticket.

comment:3 by Mariusz Felisiak, 2 years ago

Summary: Django db expressions doesn't combine MODResolve output_field when combining numeric expressions with MOD operator.
Triage Stage: UnreviewedAccepted

comment:4 by David Wobrock, 20 months ago

Cc: David Wobrock added

Hasn't this been addressed by https://github.com/django/django/pull/15271/files#diff-359ab56295cce36b9597e1d65185f695f271955617b40f43df58ce3fe76fd0c8R492?
Removing the marked line will make expressions.tests.ExpressionOperatorTests.test_lefthand_modulo_null fail with a Cannot infer type of '%%' expression involving these types: IntegerField, IntegerField. You must set output_field.

Which sounds pretty close to what is described in the issue here.
Or what am I missing? :)

in reply to:  4 comment:5 by Mariusz Felisiak, 20 months ago

Replying to David Wobrock:

Hasn't this been addressed by https://github.com/django/django/pull/15271/files#diff-359ab56295cce36b9597e1d65185f695f271955617b40f43df58ce3fe76fd0c8R492?

No, this issue is for mixed numeric types, e.g. DecimalField and IntegerField.

comment:6 by David Wobrock, 19 months ago

Has patch: set
Owner: changed from nobody to David Wobrock
Status: newassigned

comment:7 by Mariusz Felisiak, 19 months ago

Patch needs improvement: set

comment:8 by Mariusz Felisiak, 19 months ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 by GitHub <noreply@…>, 19 months ago

Resolution: fixed
Status: assignedclosed

In cff1f88:

Fixed #33464 -- Resolved output_field for combined numeric expressions with MOD operator.

Note: See TracTickets for help on using tickets.
Back to Top