#29881: Decimal data type mapping triggers bug in MySQL
-------------------------------------+-------------------------------------
     Reporter:  parander             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  mysql, decimal,      |             Triage Stage:
  numeric                            |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by parander:

Old 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.

New 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.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29881#comment:1>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.dda7207d98bbc13e9b746b478092d863%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to