﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30195	RawSQL ignores decimal_places property of DecimalField	alakae	nobody	"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"	Bug	closed	Database layer (models, ORM)	2.1	Normal	wontfix	sqlite	Dave Halter alakae	Unreviewed	0	0	0	0	0	0
