Skip to content

Commit

Permalink
Fix phonenumber Django 1.6/Python 3 unicode bug
Browse files Browse the repository at this point in the history
Django calls force_text on PhoneNumber instances when populating
a model form. Django 1.6's force_text implementation unfortunately
checks for __unicode__, which is defined in the base class.
As we're using the python_2_unicode_compatible decorator, in Python 2
__unicode__ is already overwritten by the decorator.
In Python 3, we can safely return __str__ because it returns unicode.

This was discovered by @itbabu in #1645.
  • Loading branch information
maiksprenger committed Jan 30, 2015
1 parent 7b31081 commit b57d282
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/oscar/core/phonenumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ def __str__(self):
return self.format_as(fmt)
return self.raw_input

def __unicode__(self):
# Django calls force_text on PhoneNumber instances when populating
# a model form. Django 1.6's force_text implementation unfortunately
# checks for __unicode__, which is defined in the base class.
# As we're using the python_2_unicode_compatible decorator, in Python 2
# __unicode__ is already overwritten by the decorator.
# In Python 3, we can safely return __str__ because it returns unicode.
return self.__str__()

def is_valid(self):
"""
checks whether the number supplied is actually valid
Expand Down

0 comments on commit b57d282

Please sign in to comment.