Skip to content

Commit edd9c7d

Browse files
committed
Merge pull request #3819 from m1kola/bug/DateField-to_representation-unicode-compatibility
PY2: DateField.to_representation can't work with unicode value
2 parents 057cf13 + 6b207d9 commit edd9c7d

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

rest_framework/fields.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ def to_representation(self, value):
11391139
)
11401140

11411141
if output_format.lower() == ISO_8601:
1142-
if (isinstance(value, str)):
1142+
if isinstance(value, six.string_types):
11431143
value = datetime.datetime.strptime(value, '%Y-%m-%d').date()
11441144
return value.isoformat()
11451145

tests/test_fields.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import django
77
import pytest
88
from django.http import QueryDict
9-
from django.utils import timezone
9+
from django.utils import six, timezone
1010

1111
import rest_framework
1212
from rest_framework import serializers
@@ -895,6 +895,7 @@ class TestDateField(FieldValues):
895895
outputs = {
896896
datetime.date(2001, 1, 1): '2001-01-01',
897897
'2001-01-01': '2001-01-01',
898+
six.text_type('2016-01-10'): '2016-01-10',
898899
None: None,
899900
'': None,
900901
}

0 commit comments

Comments
 (0)