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)

force_unicode.patch (800 bytes ) - added by Moof 17 years ago.
Fixes force_unicode to take Decimal values into account
models.py (716 bytes ) - added by Moof 17 years ago.
Failing tests for Decimal

Download all attachments as: .zip

Change History (5)

comment:1 by Moof, 17 years ago

Needs tests: set

Attached: A patch to fix the strings_only behaviour of django.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.

by Moof, 17 years ago

Attachment: force_unicode.patch added

Fixes force_unicode to take Decimal values into account

by Moof, 17 years ago

Attachment: models.py added

Failing tests for Decimal

comment:2 by Moof, 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 Ramiro Morales, 17 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #5903 that included a similar patch and adds a regression test.

Note: See TracTickets for help on using tickets.
Back to Top