Skip to content

Commit

Permalink
Merge pull request #316 from edx/shr/bug/revert-plat-736
Browse files Browse the repository at this point in the history
Revert "String field return empty string for None"
  • Loading branch information
Shrhawk committed Aug 12, 2015
2 parents ab0bb89 + a9348ec commit f0f0c09
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
10 changes: 1 addition & 9 deletions xblock/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,19 +808,11 @@ class String(JSONField):
MUTABLE = False

def from_json(self, value):
if value is None:
return ''
elif isinstance(value, basestring):
if value is None or isinstance(value, basestring):
return value
else:
raise TypeError('Value stored in a String must be None or a string, found %s' % type(value))

def to_json(self, value):
if value is None:
return ''
self._warn_deprecated_outside_JSONField()
return value

def from_string(self, value):
"""String gets serialized and deserialized without quote marks."""
return self.from_json(value)
Expand Down
9 changes: 1 addition & 8 deletions xblock/test/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,7 @@ def test_json_equals(self):
self.assertJSONOrSetEquals('', '')

def test_none(self):
# test for NoneType for to_string and from_string methods
test_field = String(enforce_type=True)

result_to_string = test_field.to_string(None)
self.assertEquals(result_to_string, '')

result_from_string = test_field.from_string(None)
self.assertEquals(result_from_string, '')
self.assertJSONOrSetEquals(None, None)

def test_error(self):
self.assertJSONOrSetTypeError(['a'])
Expand Down

0 comments on commit f0f0c09

Please sign in to comment.