Code

Opened 8 years ago

Closed 7 years ago

#1336 closed defect (fixed)

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

Reported by: chrisb@… Owned by: adrian
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 8 years ago.
Patch file against revision 2292 of django/core/formfields.py
usstate.patch (593 bytes) - added by SmileyChris 7 years ago.

Download all attachments as: .zip

Change History (15)

Changed 8 years ago by anonymous

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

comment:1 Changed 8 years ago by anonymous

  • Summary changed from USStateField do_html2python exception data is None to USStateField do_html2python(data) throws exception when data is None

comment:2 Changed 8 years ago by anonymous

  • Summary changed from USStateField do_html2python(data) throws exception when data is None to [patch] USStateField do_html2python(data) throws exception when data is None

comment:3 Changed 8 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

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

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

  • Keywords reopen added

Changed 7 years ago by SmileyChris

comment:6 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Unreviewed to Ready for checkin

Obviously needs a better patch then :)

comment:7 Changed 7 years ago by adrian

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Ready for checkin to Accepted

comment:8 Changed 7 years ago by adrian

  • Keywords reopen removed

comment:9 Changed 7 years ago by SmileyChris

  • Triage Stage changed from Accepted to Ready for checkin

Looks ready to me...

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

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

comment:11 Changed 7 years ago by SmileyChris

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 7 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 7 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.