Breaking change: DateTimeField validation parsing #9156
Unanswered
RignonNoel
asked this question in
Potential Issue
Replies: 1 comment 6 replies
-
I am open to see a PR with a failing test case atleast |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We upgraded a Django project to the new version of Django (
4.2.5
) and DRF (3.14.0
) and some of ours unit test failed due to breaking changes on theDateTimeField()
parsing validation.Example of serializer:
Example of data we tested:
Example of exception we expected before:
Now, it seems that
2021-03-13
is valid... But it's not at all matching the format proposed in the default error message that DRF use:YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].
Different option i think:
00:00:00
time on datetime in place of the error message they got beforeparse_datetime()
more clearly defined to avoid futur problem)Here are my research
django-rest-framework/rest_framework/settings.py
Line 107 in f56b85b
django-rest-framework/rest_framework/fields.py
Lines 1177 to 1198 in f56b85b
We see here that DRF clearly use
ISO_8601
in the default settings and use the djangoparse_datetime()
function to make the logic attachedhttps://github.com/django/django/blame/656192c2c96bb955a399d92f381e38fe2254fe17/django/utils/dateparse.py#L104-L130
But we see here that Django try to use
datetime.fromisoformat()
first since this commit of @kezabelle andfromisoformat()
allow a LOT MORE format than before as you can see on their documentationhttps://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat
Beta Was this translation helpful? Give feedback.
All reactions