#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.

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.a8afda6f1063dd84ce1fbc0b5c46c869%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to