DateTimeField enforce_timezone() cannot handle DST information #8231
Unanswered
alxnik
asked this question in
Potential Issue
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We have a web API with USE_TZ enabled which receives naive datetimes. In the last change of DST, the API started responding HTTP 400 errors for values between 03:00 and 04:00 (local) due to pytz raising AmbiguousTimeError.
Although this is somewhat expected behaviour, if the client doesn't have the DST information (and if the client sends naive datetime then most probably it doesn't have this information), there is no way to receive these values.
2 proposed solutions would be to:
We have worked around the issue by sublcassing & overriding enforce_timezone() as below and then doing custom conversion in the validate_() of the serializer.
Although our solution works perfectly fine, this seems like a generic enough issue to warrant some kind of handling logic in DRF, or maybe a warning in the documentation.
Beta Was this translation helpful? Give feedback.
All reactions