#36574: Regression: DecimalField values are no longer quantized before written 
to
the DB
-------------------------------------+-------------------------------------
     Reporter:  Aaron Mader          |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  5.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

 I also share Tim's position; if input validation is not performed then
 it's down to how the database backend implements storeage (e.g. SQLite
 will allow to store pretty much anything in any field)

 Do you happen [https://dbfiddle.uk/DiVEJQCN to be running MySQL in non-
 strict mode] which allows invalid input to be stored in the first place? I
 cannot reproduce with the following test against MySQL with strict mode
 enabled (which is the default). In strict mode the data is truncated as
 expected

 {{{#!diff
 diff --git a/tests/lookup/test_decimalfield.py
 b/tests/lookup/test_decimalfield.py
 index d938ccf649..d4adb859c7 100644
 --- a/tests/lookup/test_decimalfield.py
 +++ b/tests/lookup/test_decimalfield.py
 @@ -35,3 +35,9 @@ def test_lt(self):
      def test_lte(self):
          qs = self.queryset.filter(qty_needed__lte=0)
          self.assertCountEqual(qs, [self.p1, self.p2])
 +
 +    def test_eq_truncation(self):
 +        from decimal import Decimal
 +
 +        obj = Product.objects.create(name="Product1",
 qty_target=Decimal("2000.003"))
 +
 self.assertEqual(Product.objects.get(qty_target=Decimal("2000.00")), obj)
 }}}

 Note that the test do fail when MySQL strict mode is disabled and as
 expected on SQLite [https://www.sqlite.org/datatypes.html where pretty
 much any data type is stored as text].

 I let others chime in but to me this is a case of ''invalid'' or
 ''wontfix''
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36574#comment:3>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070198eba7c010-ab52e47b-c0c5-4ed2-bcdb-f45ddf9576bb-000000%40eu-central-1.amazonses.com.

Reply via email to