#32793: Problem with decimal field when upgrade version
-------------------------------------+-------------------------------------
               Reporter:  mohiz      |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  3.2
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  decimal
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 A simple example such as:

 {{{
 #!python
 from django.db import models

 class Foo(models.Model):
     amount = models.DecimalField(
         null=False,
         decimal_places=18,
         max_digits=44)


 # A simple insertion example
 from api.models import Foo
 from django.db.models import F
 from decimal import Decimal

 f = Foo.objects.create(amount=Decimal('0.5'))
 f.amount = F('amount') - Decimal('0.4')
 f.save(update_fields=['amount', ])
 f.refresh_from_db()
 print(f.amount)
 }}}
 This creates an unexpected result (0.099999999999999980) in new version,
 but in previous version it was ok. I checked the difference and I found
 that new version sends a decimal value in a quotation, but in the previous
 version it would send in number format. Below is the query for two
 different versions:
 {{{
 #!mysql
 3.1
 UPDATE `api_foo` SET `amount` = (`api_foo`.`amount` - 0.4) WHERE
 `api_foo`.`id` = 1

 3.2
 UPDATE `api_foo` SET `amount` = (`api_foo`.`amount` - '0.4') WHERE
 `api_foo`.`id` = 1
 }}}

 I am using mysql-8.0.19.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32793>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/048.2896c0a509fa2e6a521496038848a11d%40djangoproject.com.

Reply via email to