Changes between Initial Version and Version 1 of Ticket #29845


Ignore:
Timestamp:
Oct 12, 2018, 9:38:05 AM (6 years ago)
Author:
Tim Graham
Comment:

Reproduced on master at 910548634a23f7a3346158e93de0ab308ae52c0c.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #29845

    • Property Triage Stage UnreviewedAccepted
    • Property Summary django orm cast float field to decimal causes MySQL errorCasting FloatField to DecimalField causes MySQL/MariaDB SQL syntax error
  • Ticket #29845 – Description

    initial v1  
    33Seen in django 1.11.16 on MariaDB.
    44
    5 
    65Model:
    7 
    8 
    96{{{
    107class MyModel(models.Model):
    11  floatfield = models.FloatField('My FloatField')
    12  decimalfield = models.DecimalField(_("My DecimalField"), decimal_places=2, max_digits=12, validators=[MinValueValidator(Decimal('0.01'))])
     8    floatfield = models.FloatField()
     9    decimalfield = models.DecimalField(decimal_places=2, max_digits=12)
    1310}}}
    1411
    15 
    1612Query:
    17 
    18 
    1913{{{
    2014MyModel.objects.all().annotate(
    21             floatfield_decimal=Cast('floatfield', DecimalField(max_digits=8, decimal_places=2))).aggregate(
    22             revenue=Sum(F('floatfield_decimal') * F('decimalfield')))['revenue']
    23 
     15    floatfield_decimal=Cast('floatfield', DecimalField(max_digits=8, decimal_places=2))).aggregate(
     16    revenue=Sum(F('floatfield_decimal') * F('decimalfield'))
     17)['revenue']
    2418}}}
    2519
    2620Then I see this error:
    27 
    28 
    29 
    3021{{{
    3122{ProgrammingError}(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'numeric(8, 2)) AS `floatfield_decimal`, `myclass`.`decimalfield' at line 1")
    32 
    3323}}}
    3424
    35 I guess the `numeric` should be `Decimal`... It's not possible to examite the query further from the debugger.
     25I guess the `numeric` should be `Decimal`... It's not possible to examine the query further from the debugger.
Back to Top