Skip to content

DateTimeField to_representation can handle strings. Fixes #4013.#4019

Closed
calumcalder wants to merge 3 commits intoencode:masterfrom
calumcalder:master
Closed

DateTimeField to_representation can handle strings. Fixes #4013.#4019
calumcalder wants to merge 3 commits intoencode:masterfrom
calumcalder:master

Conversation

@calumcalder
Copy link
Copy Markdown

Fixes issue with DateTimeField described in #4013.

Comment thread rest_framework/fields.py Outdated
return value

if output_format.lower() == ISO_8601:
if isinstance(value, str):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be six.binary_type

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not be six.string_types?

Python 2.7.6
>>> isinstance('2001-01-01T01:01', six.binary_type)
True
>>> isinstance('2001-01-01T01:01', six.string_types)
True

Whereas

Python 3.4.3
>>> isinstance('2001-01-01T01:01', six.binary_type)
False
>>> isinstance('2001-01-01T01:01', six.string_types)
True

Given that Python 2's datetime.datetime.strptime function does not
accept '+HHMM' strings with the format directive '%z', the tests for
accepting such strings have been ommitted for python 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants