#30195: RawSQL ignores decimal_places property of DecimalField
-------------------------------------+-------------------------------------
               Reporter:  alakae     |          Owner:  nobody
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  2.1
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When updating Django in our environment from 2.0.6 to 2.1.7 we have
 noticed that {{{RawSQL}}} does not take into account the
 {{{decimal_places}}} property of a {{{DecimalField}}} passed as
 {{{output_field}}}. Please consider the following example:

 {{{#!python
 def currency_field(*, decimal_places=2, **kwargs):
     return models.DecimalField(max_digits=19,
 decimal_places=decimal_places, **kwargs)


 class A(models.Model):
     x = currency_field()


 def test_demo():
     A.objects.create(x=Decimal('1.3333333333333'))
     raw_sql = RawSQL(2.3333333333333, (), currency_field())

     qs = A.objects.all()
     res = qs.annotate(val=raw_sql).get()
     assert res.x == Decimal('1.33')
     assert res.val == Decimal('2.33')
 }}}

 On Django 2.0.6 the test passes. When using Django 2.1.7 the following
 error is returned:

 {{{#!python
 >       assert res.val == Decimal('2.33')
 E       AssertionError: assert Decimal('2.33333333333330') ==
 Decimal('2.33')
 E        +  where Decimal('2.33333333333330') = <A: A object (1)>.val
 E        +  and   Decimal('2.33') = Decimal('2.33')
 }}}

 Since this change does not seem to be mentioned in
 [https://docs.djangoproject.com/en/2.1/releases/2.1/] we suspect that this
 might be a bug. I am using Python 3.6.5 and sqlite 3.27.1.

 Related to: https://code.djangoproject.com/ticket/23941

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30195>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.f472aafb92f88a2994f094a265c5c92a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to