Opened 6 years ago

Last modified 6 years ago

#29881 closed Bug

Decimal data type mapping triggers bug in MySQL — at Initial Version

Reported by: Par Andersson Owned by: nobody
Component: Database layer (models, ORM) Version: 2.1
Severity: Normal Keywords: mysql, decimal, numeric
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top