-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix UnicodeDecodeError
, which can occur on serializer repr
.
#2270
Labels
Milestone
Comments
My patch utils/representation.py def serializer_repr(serializer, indent, force_many=None):
ret = field_repr(serializer, force_many) + ':'
indent_str = ' ' * indent
if force_many:
fields = force_many.fields
else:
fields = serializer.fields
for field_name, field in fields.items():
field_name = field_name.encode('utf-8')
ret += '\n' + indent_str + field_name + ' = '
if hasattr(field, 'fields'):
ret += serializer_repr(field, indent + 1)
elif hasattr(field, 'child'):
ret += list_repr(field, indent + 1)
elif hasattr(field, 'child_relation'):
ret += field_repr(field.child_relation, force_many=field.child_relation)
else:
ret += field_repr(field)
if serializer.validators:
ret += '\n' + indent_str + 'class Meta:'
ret += '\n' + indent_str + ' validators = ' + smart_repr(serializer.validators)
return ret test.py class Location(models.Model):
name = models.CharField(max_length=10, unique=True)
class LocationSerializer(serializers.ModelSerializer):
class Meta:
model = Location
l = Location(name=u'한국') <<< Unicode
l.save()
s = LocationSerializer(instance=l)
print s
LocationSerializer(instance=<Location: 한국>):
id = IntegerField(label='ID', read_only=True)
name = CharField(max_length=10, validators=[<UniqueValidator(queryset=Location.objects.all())>]) |
Thanks for the report! :) |
@tomchristie Thanks ! |
tomchristie
changed the title
serializer_repr func has UnicodeDecodeError
Fix Dec 15, 2014
UnicodeDecodeError
, which can occur on serializer repr
.
This was referenced Mar 9, 2017
This was referenced Oct 16, 2017
This was referenced Nov 6, 2017
This was referenced Nov 14, 2017
This was referenced Dec 10, 2017
This was referenced Dec 20, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry.. I can't speak english well.
Please, see some codes.
The text was updated successfully, but these errors were encountered: