-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
DateField and DateTimeField not handling empty values correctly #2687
Comments
I'm experiencing the same problem |
I have just realized using serializers fields definition kinda solve this problem. See. Here is how I'm using it:
It works when my deadline field has values. My problem now is that my deadline field is not mandatory, so trying adding more option to it fails to behave has expected. I have tried playing with
|
@tomchristie I can work on a fix for this; would the appropriate test output dict be...?
|
@ryangallen That looks right to me. |
Cool, here's a pull req. #2869 |
Closed by #2869. |
This results in the same error as mentioned in #2656, but has a different reproduction and implications. A test case like the following:
Results in an error like:
This is because the submitted data does not contain a 'my_date' field (which is valid in this situation) and that results in the empty string being sent as the
value
parameterDateField.to_representation
, which proceeds to attempt to callisoformat()
on it.I'm happy to submit a PR, but I wanted to first check that I wasn't missing something and check to see how you actually wanted to handle it. Maybe just return the value if it's None or ''? Or more complex string handling as requested in #2656? Or maybe something else should happen earlier to prevent empty values from even getting to
to_representation
?The text was updated successfully, but these errors were encountered: