Opened 13 years ago
Closed 13 years ago
#16570 closed Bug (fixed)
allow DecimalFields with max_digits == decimal_places
Reported by: | Dan Watson | Owned by: | kenth |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
This was discussed on django-dev here:
https://groups.google.com/d/topic/django-developers/TvMNbPWwetY/discussion
Essentially, the fix for #7726 caused a validation error for max_digits == decimal_places, which is a valid numeric type in the database.
Attachments (3)
Change History (11)
by , 13 years ago
Attachment: | 16570.diff added |
---|
comment:1 by , 13 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
The documentation needs to be changed, too:
.. attribute:: DecimalField.max_digits The maximum number of digits allowed in the number. Note that this number must be greater than ``decimal_places``, if it exists.
comment:2 by , 13 years ago
Patch needs improvement: | unset |
---|
comment:3 by , 13 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
Feels like there should be a test included here. However, my reading of the original ticket we are modifying is that there was a problem with Django normalising .1234 to be 0.1234, so maybe a test is hard to write.
However, failing an argument that it's impossible to test at the Django level (and hence only relevant when Django creates the table), it needs a test to avoid future regressions.
comment:4 by , 13 years ago
I think the problem was that Django used to do it's own validation of decimals (see #7064 and the associated patch). It seems now, Django simply tries the Decimal constructor and catches any exception. Since Decimal('0.123') == Decimal('.123')
(both get normalized to include the leading 0) I don't think this is an issue.
comment:6 by , 13 years ago
Owner: | changed from | to
---|
by , 13 years ago
Attachment: | 16570-3.diff added |
---|
Updated patch to account for refactoring in #16681
comment:7 by , 13 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
Patch against trunk r16579, all tests pass.