[Django] #28915: Regression in value of DecimalFields on SQLite in Django 2.0

11 views
Skip to first unread message

Django

unread,
Dec 11, 2017, 2:45:13 PM12/11/17
to django-...@googlegroups.com
#28915: Regression in value of DecimalFields on SQLite in Django 2.0
-------------------------------------+-------------------------------------
Reporter: Raphael | Owner: nobody
Michel |
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Release | Keywords:
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
With Django 1.11, when reading the value of a DecimalField from the
database, the Decimal is always returned with the precision of the
DecimalField, i.e. if the field has 2 decimal places, I always get a
Decimal with two decimal places as well.

With Django 2.0, I get a rounded decimal with no more decimal places.

Sample:

{{{
obj = Foo.objects.create(a="bar", d=Decimal('8.320'))
obj.refresh_from_db()

print(repr(obj.d))
}}}

This will output `Decimal('8.320')` on Django 1.11 but `Decimal('8.32')`
on Django 2.0.


For me (and likely many others) this is quite critical: For example, if
you use DecimalFields to store amounts of money in a currency that always
has two places, you can just pass the databases to `localize()` and get a
user-friendly representation. This is no longer possible, as you would
first need to call quantize in every single place which would be quite an
effort to do in a large codebasis.

Since there is no mention of this in the release notes, I believe this is
an unwanted regression and hope it can be fixed in 2.0.2 or the like.

I wrote a
[https://github.com/raphaelm/django/commit/6c682b619e88f69e4c75b890f8c3eed8fcd1aa87
regression test] for the problem and ran `git bisect` to identify that the
problem was introduced in commit
[https://github.com/django/django/commit/a146b65628e702a9a3ed5be21542ca45366fbb29
a146b6562].

I did not find a way to keep the performance gain of this commit without
introducing this regression, so I strongly ask to revert that commit
altogether for now (and add my regression test, if wanted) until someone
has a better idea how to optimize this.

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

Django

unread,
Dec 11, 2017, 2:54:35 PM12/11/17
to django-...@googlegroups.com
#28915: Regression in handling of DecimalField values on SQLite in Django 2.0
-------------------------------------+-------------------------------------
Reporter: Raphael Michel | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

Django

unread,
Dec 11, 2017, 5:25:16 PM12/11/17
to django-...@googlegroups.com
#28915: Regression in handling of DecimalField values on SQLite in Django 2.0
-------------------------------------+-------------------------------------
Reporter: Raphael Michel | Owner: nobody
Type: Bug | Status: new

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | 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 Simon Charette):

* cc: Sergey Fedoseev (added)
* stage: Unreviewed => Accepted


Comment:

Thank you for your detailed report Raphael.

Could you confirm the issue is only present on SQLite? How do other
database backend behave in this regard?

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

Django

unread,
Dec 11, 2017, 7:11:30 PM12/11/17
to django-...@googlegroups.com
#28915: Regression in handling of DecimalField values on SQLite in Django 2.0
-------------------------------------+-------------------------------------
Reporter: Raphael Michel | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | 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 Sergey Fedoseev):

* status: new => assigned
* owner: nobody => Sergey Fedoseev


--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:3>

Django

unread,
Dec 12, 2017, 10:31:49 AM12/12/17
to django-...@googlegroups.com
#28915: Regression in handling of DecimalField values on SQLite in Django 2.0
-------------------------------------+-------------------------------------

Reporter: Raphael Michel | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | 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 Sergey Fedoseev):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9457 PR]

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

Django

unread,
Dec 13, 2017, 2:50:55 AM12/13/17
to django-...@googlegroups.com
#28915: DecimalField truncates trailing zeros in the fractional part on SQLite

-------------------------------------+-------------------------------------
Reporter: Raphael Michel | Owner: Sergey
| Fedoseev
Type: Bug | Status: assigned
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | 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 Tim Graham):

* stage: Accepted => Ready for checkin


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

Django

unread,
Dec 13, 2017, 3:23:57 AM12/13/17
to django-...@googlegroups.com
#28915: DecimalField truncates trailing zeros in the fractional part on SQLite
-------------------------------------+-------------------------------------
Reporter: Raphael Michel | Owner: Sergey
| Fedoseev
Type: Bug | Status: closed

Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | 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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"6fd6d8383f48ea2fe4e058725fa30529a083e9a5" 6fd6d838]:
{{{
#!CommitTicketReference repository=""
revision="6fd6d8383f48ea2fe4e058725fa30529a083e9a5"
Fixed #28915 -- Prevented SQLite from truncating trailing zeros in the
fractional part of DecimalField.

This reverts commit a146b65628e702a9a3ed5be21542ca45366fbb29 and adds
a test for the regression.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:6>

Django

unread,
Dec 13, 2017, 3:24:02 AM12/13/17
to django-...@googlegroups.com
#28915: DecimalField truncates trailing zeros in the fractional part on SQLite
-------------------------------------+-------------------------------------
Reporter: Raphael Michel | Owner: Sergey
| Fedoseev
Type: Bug | Status: closed
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | 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
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"0f7ca1e8786ac04ad819a147a69ab5d4054e4d39" 0f7ca1e8]:
{{{
#!CommitTicketReference repository=""
revision="0f7ca1e8786ac04ad819a147a69ab5d4054e4d39"
[2.0.x] Fixed #28915 -- Prevented SQLite from truncating trailing zeros in


the fractional part of DecimalField.

This reverts commit a146b65628e702a9a3ed5be21542ca45366fbb29 and adds
a test for the regression.

Backport of 6fd6d8383f48ea2fe4e058725fa30529a083e9a5 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:7>

Django

unread,
Dec 20, 2017, 12:02:53 PM12/20/17
to django-...@googlegroups.com
#28915: DecimalField truncates trailing zeros in the fractional part on SQLite
-------------------------------------+-------------------------------------
Reporter: Raphael Michel | Owner: Sergey
| Fedoseev
Type: Bug | Status: closed
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Release blocker | 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
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"7c939ae6e461323ad63aae105182768611ff0a94" 7c939ae]:
{{{
#!CommitTicketReference repository=""
revision="7c939ae6e461323ad63aae105182768611ff0a94"
[2.0.x] Refs #28932 -- Skipped the failing test for refs #28915 on Oracle.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:8>

Reply all
Reply to author
Forward
0 new messages