﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
17147	DecimalField causes inline formsets to disappear	leith.john@…	Cliff Dyer	"I have a client who typed non-numeric characters in a DecimalField (for price). When he saved the form returned but the inline formset had vanished.

I think when the characters came to the DecimalField, it raised an exception which caused the inline to crash and thus disappear.

in django.forms.fields:

{{{
    def to_python(self, value):
        """"""
        Validates that the input is a decimal number. Returns a Decimal
        instance. Returns None for empty values. Ensures that there are no more
        than max_digits in the number, and no more than decimal_places digits
        after the decimal point.
        """"""
        if value in validators.EMPTY_VALUES:
            return None
        if self.localize:
            value = formats.sanitize_separators(value)
        value = smart_str(value).strip()
        try:
            value = Decimal(value)
        except DecimalException:
            # >>> i think this is the culprit, should it throw validationerrors here?
            # about line 292
            raise ValidationError(self.error_messages['invalid'])
        return value
}}}

I know my client shouldn't have put characters in there of course, but it's very possible to accidentally put in wrong data in a form field. I think the decimal field should display an error rather than raising an exception at this point.

I'm using this for now:

{{{
        class SafeDecimalField(forms.DecimalField):
            def to_python(self, value):
                try:
                    return super(SafeDecimalField, self).to_python(value)
                except Exception, ex:
                    return Decimal(""0.0"")
}}}
"	Bug	closed	Forms	1.2	Normal	needsinfo	admin formset		Accepted	0	0	0	0	0	0
