Opened 17 years ago
Closed 17 years ago
#6501 closed (duplicate)
DecimalField does not correctly set default value
Reported by: | Moof | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
DecimalField's default
argument appears to set the field to a unicode rather than a Decimal instance, this then makes calculations involving Decimals not work.
I've attached a small models.py file that can be used to check the behaviour, including expected results and the actual ones.
There's a smallish bug that Decimal("0.00")
doesn't retain its precision on loading, but this may be a python bug.
Attachments (2)
Change History (5)
comment:1 by , 17 years ago
Needs tests: | set |
---|
by , 17 years ago
Attachment: | force_unicode.patch added |
---|
Fixes force_unicode to take Decimal values into account
comment:2 by , 17 years ago
Has patch: | set |
---|
Removed the precision tests. That should be in another ticket, and needs a fuller discussion.
This ticket and patch is merely for the default value problem.
comment:3 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Duplicate of #5903 that included a similar patch and adds a regression test.
Attached: A patch to fix the
strings_only
behaviour ofdjango.utils.encoding.force_unicode()
which seems to be the cause of the problem, as it checks for certain types and misses out Decimal.This fixes the default being returned as a unicode rather than a Decimal.
However, I can't seem to find an obvious place in the test suite to add these tests.