#36574: Regression: DecimalField values are no longer quantized before written
to
the DB
-------------------------------------+-------------------------------------
Reporter: Aaron Mader | Owner: (none)
Type: Bug | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Aaron Mader:
Old description:
> Steps to reproduce:
> 1. Create a new project using the mysql backend
> 2. Create this model:
> {{{#!python
> class Apple(models.Model):
> weight = models.DecimalField(max_digits=4, decimal_places=1)
> }}}
> 3. Create an instance of this record with input outside of the
> quantization limits
> {{{#!python
> from decimal import Decimal
> Apple.objects.create(
> weight = Decimal("1.01"),
> )
> }}}
> 4. Attempt to fetch the record by the (expected) adjusted value
> {{{#!python
> from decimal import Decimal
> Apple.objects.filter(
> weight = Decimal("1.0"),
> )
> }}}
>
> Specifically, this change in behaviour was introduced in django 5.2.0,
> with prior versions of django quantizing the input value (`1.01`) to an
> acceptable value (`1.0`) before writing the value to the database.
> I believe that change was introduced in pull request:
> https://github.com/django/django/pull/18895
New description:
Steps to reproduce:
1. Create a new project using the mysql backend
2. Create this model:
{{{#!python
class Apple(models.Model):
weight = models.DecimalField(max_digits=4, decimal_places=1)
}}}
3. Create an instance of this record with input outside of the
quantization limits
{{{#!python
from decimal import Decimal
Apple.objects.create(
weight = Decimal("1.01"),
)
}}}
4. Attempt to fetch the record by the (expected) adjusted value
{{{#!python
from decimal import Decimal
Apple.objects.filter(
weight = Decimal("1.0"),
)
}}}
Result:
With django 5.2.0, the filter query fails with 0 results.
With django 5.1.11, the filter query success, returning the created
record.
Specifically, this change in behaviour was introduced in django 5.2.0,
with prior versions of django quantizing the input value (`1.01`) to an
acceptable value (`1.0`) before writing the value to the database.
I believe that change was introduced in pull request:
https://github.com/django/django/pull/18895
--
--
Ticket URL: <https://code.djangoproject.com/ticket/36574#comment:1>
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 visit
https://groups.google.com/d/msgid/django-updates/01070198e8219f95-5f7132da-84d6-4c47-b734-22a64c0805d0-000000%40eu-central-1.amazonses.com.