﻿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
29881	Invalid SQL on MySQL with Cast to DecimalField	Par Andersson	nobody	"Casting to DecimalField triggers a bug in MySQL due to DecimalField being mapped to numeric.

Example:
{{{
Model.objects.annotate(bug=Cast('somefield', DecimalField(10,2)))
}}}
Will generate an error from MySQL, the issue is that MySQL has an issue where it's not possible to cast to numeric as reported here:
https://bugs.mysql.com/bug.php?id=84558

With Django this happens due to the data type mapping defined in data_types  (db/backends/mysql/base.py:111 to be exact):

{{{
'DecimalField': 'numeric(%(max_digits)s, %(decimal_places)s)',
}}}
I propose that this line is changed to:
{{{
'DecimalField': 'decimal(%(max_digits)s, %(decimal_places)s)',
}}}

as this seems to be a simple work around for the underlying issue.





"	Bug	closed	Database layer (models, ORM)	2.1	Normal	duplicate	mysql, decimal, numeric		Unreviewed	1	0	0	0	1	0
