#15708: Regression in Forms: KeyError if trying to access nonvalid input from required field --------------------------------------+---------------------- Reporter: jonescb | Owner: nobody Status: closed | Milestone: Component: Forms | Version: 1.3 Resolution: needsinfo | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | --------------------------------------+----------------------
Comment (by jonescb): Ok, you're right 1.2 behaves the same way, so it's not a regression, but I think it could be handled better. At least for CharFields and fields that derive CharField, cleaned_data could default to an empty string. Other fields could possibly default to other values. AFAIK, a blank string won't raise an exception during any string processing just because it's blank. If the field is set to required, Django should set the form as being invalid so that a custom clean() written by an amateur like myself that wasn't expecting an empty field won't end up with a 500 error and it can be handled more gracefully. Custom clean()'s might have to call super.clean() to do this I believe. Django already does this for required=False. Blank CharFields yield an empty string in cleaned_data. To me it seems like a strange behavior for Django to give a nice error message for invalid fields, but if your clean() method has to process a field, it will crash unless you catch the exception. Maybe I'm just rationalizing my mistake in not catching the exception, but I think it would be more consistent and make life easier for developers if Django set a blank or default value. I'll leave the ticket as closed because I doubt anyone would agree with me. -- Ticket URL: <http://code.djangoproject.com/ticket/15708#comment:4> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.