Opened 11 years ago

Closed 10 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: master
Severity: normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 11 years ago.
Patch file against revision 2292 of django/core/formfields.py
usstate.patch (593 bytes) - added by Chris Beaven 10 years ago.

Download all attachments as: .zip

Change History (15)

Changed 11 years ago by anonymous

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

comment:1 Changed 11 years ago by anonymous

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

comment:2 Changed 11 years ago by anonymous

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

comment:3 Changed 11 years ago by Jacob

Resolution: fixed
Status: newclosed

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

comment:4 Changed 10 years ago by Gary Wilson <gary.wilson@…>

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

comment:5 Changed 10 years ago by Gary Wilson <gary.wilson@…>

Keywords: reopen added

Changed 10 years ago by Chris Beaven

Attachment: usstate.patch added

comment:6 Changed 10 years ago by Chris Beaven

Triage Stage: UnreviewedReady for checkin

Obviously needs a better patch then :)

comment:7 Changed 10 years ago by Adrian Holovaty

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

comment:8 Changed 10 years ago by Adrian Holovaty

Keywords: reopen removed

comment:9 Changed 10 years ago by Chris Beaven

Triage Stage: AcceptedReady for checkin

Looks ready to me...

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

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

comment:11 Changed 10 years ago by Chris Beaven

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 Changed 10 years ago by Gary Wilson <gary.wilson@…>

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

comment:13 Changed 10 years ago by Adrian Holovaty

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