Opened 18 years ago

Closed 17 years ago

#1336 closed defect (fixed)

[patch] USStateField do_html2python(data) throws exception when data is None

Reported by: chrisb@… Owned by: Adrian Holovaty
Component: Core (Other) Version: dev
Severity: normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The USStateField do_html2python method calls "upper()" on the data passed to it. If the "data" is None, as it is in the case where you allow users to not select a state (i.e. state is not required), then it calls upper() on "None" which fails.

Patch is simple - test data before returning data.upper(), otherwise just return the data.

Index: formfields.py
===================================================================
--- formfields.py	(revision 2292)
+++ formfields.py	(working copy)
@@ -875,7 +875,10 @@
             raise validators.CriticalValidationError, e.messages
 
     def html2python(data):
-        return data.upper() # Should always be stored in upper case
+        if data:
+            return data.upper() # Should always be stored in upper case
+        else:
+            return data
     html2python = staticmethod(html2python)
 
 class CommaSeparatedIntegerField(TextField):

Attachments (2)

django-core-formfields.py.diff (566 bytes ) - added by anonymous 18 years ago.
Patch file against revision 2292 of django/core/formfields.py
usstate.patch (593 bytes ) - added by Chris Beaven 17 years ago.

Download all attachments as: .zip

Change History (15)

by anonymous, 18 years ago

Patch file against revision 2292 of django/core/formfields.py

comment:1 by anonymous, 18 years ago

Summary: USStateField do_html2python exception data is NoneUSStateField do_html2python(data) throws exception when data is None

comment:2 by anonymous, 18 years ago

Summary: USStateField do_html2python(data) throws exception when data is None[patch] USStateField do_html2python(data) throws exception when data is None

comment:3 by Jacob, 18 years ago

Resolution: fixed
Status: newclosed

(In [2427]) Fixed #1336 -- made USStateField work correctly when data is None (thanks, chrisb)

comment:4 by Gary Wilson <gary.wilson@…>, 17 years ago

The patch that fixed this was undone in [3785], so now this bug is back.

comment:5 by Gary Wilson <gary.wilson@…>, 17 years ago

Keywords: reopen added

by Chris Beaven, 17 years ago

Attachment: usstate.patch added

comment:6 by Chris Beaven, 17 years ago

Triage Stage: UnreviewedReady for checkin

Obviously needs a better patch then :)

comment:7 by Adrian Holovaty, 17 years ago

Resolution: fixed
Status: closedreopened
Triage Stage: Ready for checkinAccepted

comment:8 by Adrian Holovaty, 17 years ago

Keywords: reopen removed

comment:9 by Chris Beaven, 17 years ago

Triage Stage: AcceptedReady for checkin

Looks ready to me...

comment:10 by Gary Wilson <gary.wilson@…>, 17 years ago

Just note that putting this back should probably mean that #2685 gets re-opened.

comment:11 by Chris Beaven, 17 years ago

This isn't just "putting it back". The patch in [2427] incorrectly assumed that '' == None (even though the patch in this ticket was correct, funnily enough).

comment:12 by Gary Wilson <gary.wilson@…>, 17 years ago

Yes, you are right. So #2685 should not get re-opened when your patch is applied.

comment:13 by Adrian Holovaty, 17 years ago

Resolution: fixed
Status: reopenedclosed

(In [4422]) Fixed #1336 -- USStateField no longer throws exception when data is None

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