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.
--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:1>
* 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>
* status: new => assigned
* owner: nobody => Sergey Fedoseev
--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:3>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/9457 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28915#comment:5>
* 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>
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>
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>