Hi,
I would like to share some thoughts regarding django.db.models.DecimalField:
.. (A) silent rounding issue:
when a decimal value is saved in db
its decimal digits exceeding decimal_places are rounded off using
.quantize(). Rounding defaults to ROUND_HALF_EVEN (python default).
There is no mention of this behavior in docs.
.. (B) no model validation for decimal digits:
.full_clean() does not raise any exception:
- if the value has too many decimal digits
- or if value has too many digits
other fields, like CharField, do not validate values that exceed fields
constraints
.. (C) errors on save:
decimal values exceeding field's digits boundaries (decimal or total) make
.save() raise decimal.InvalidOperation exceptions
In my opinion they should be fixed in a backwards-incompatible way!:
(A) django shuld not round decimal values silently before saving, if the
value has too many decimal digits,
raise an exception (just like for values that have too many digits)
(B) decimalfield shoud not validate values that exceed its max_digits and
decimal_places constraints
(C) leave as is, but if you solve (A) and (B) it's not that bad
I have a small django testcase that better explains the problem and proposed
solution(s)
What do you think?
Marco
--
You received this message because you are subscribed to the Google Groups "Django
developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.