Opened 12 years ago

Closed 12 years ago

Last modified 2 years ago

#4518 closed (fixed)

Null string in DecimalField results in error: _raise_error, line 2267

Reported by: Richard House <Richard.House@…> Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: Keywords: DecimalField
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I am running the django web server/sqlite on WinXP with Python 2.4 and the latest django SVN version. In keeping up with the FloatField to DecimalField changes I came across an error in both the admin pages and user pages with one of my apps.
In the debug page (excellent feature), an InvalidOperation was being raised at location "C:\Python24\lib\ in _raise_error, line 2267".

I traced the cause to some of my DecimalField values had empty string values at some stage of the process. I have blank=True and null=True on that field. A change to typecast_decimal function at line 96 of C:
\Python24\Lib\site-packages\django\db\backends\ solved the problem.

def typecast_decimal(s):
    if s is None:
        return None
    return decimal.Decimal(s)


def typecast_decimal(s):
    if s is None or s == '':  ### Change
        return None
    return decimal.Decimal(s)

Suggested for a SVN change.

Change History (2)

comment:1 Changed 12 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [5450]) Fixed #4518 -- Added handling of empty strings in typecast_decimal() for
SQLite's benefit. Thanks, Richard House.

comment:2 Changed 2 years ago by Tim Graham <timograham@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

In bb91c0a4:

Refs #4518 -- Removed handling of empty strings in typecast_decimal().

It's unclear if the original change was needed, but it seems unneeded now.
Reverted 6fc10f50b0c9b877fffcad4893056cb91fa66b4f.

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