#23680: DecimalField and Postgres ORM produces incorrect SQL on filter comparison ----------------------------------------------+-------------------- Reporter: bufke | Owner: nobody Type: Bug | Status: new Component: Database layer (models, ORM) | Version: 1.6 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Easy pickings: 0 | UI/UX: 0 ----------------------------------------------+-------------------- Create a DecimalField like
{{{ max_grade = models.DecimalField(max_digits=5, decimal_places=2) }}} Set the field. Run a filter like {{{ In [11]: GradeScaleRule.objects.get(id=1).max_grade Out[11]: Decimal('59.99') In [12]: GradeScaleRule.objects.filter(max_grade=59.99) Out[12]: [] In [13]: GradeScaleRule.objects.filter(max_grade=Decimal(59.99)) Out[13]: [] }}} Here is the sql generated. {{{ SELECT "sis_gradescalerule"."id", "sis_gradescalerule"."min_grade", "sis_gradescalerule"."max_grade", "sis_gradescalerule"."letter_grade", "sis_gradescalerule"."numeric_scale", "sis_gradescalerule"."grade_scale_id" FROM "sis_gradescalerule" WHERE "sis_gradescalerule"."max_grade" = 59.99000000000000198951966012828052043914794921875 }}} Here is a psql statement showing the 59.99 max_grade is saved correctly. {{{ postgres=# select * from sis_gradescalerule; id | min_grade | max_grade | letter_grade | numeric_scale | grade_scale_id ----+-----------+-----------+--------------+---------------+---------------- 1 | 50.00 | 59.99 | F | 1.00 | 1 }}} The ORM code works fine with sqlite. -- Ticket URL: <https://code.djangoproject.com/ticket/23680> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/048.4823eaeb7761bc8fa74fdc6aef2fbb67%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.