Skip to content
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

timestamp 0 is not valid for DateTime('timestamp') #2133

Closed
flydzen opened this issue Jun 2, 2023 · 1 comment · Fixed by #2264
Closed

timestamp 0 is not valid for DateTime('timestamp') #2133

flydzen opened this issue Jun 2, 2023 · 1 comment · Fixed by #2264
Labels

Comments

@flydzen
Copy link

flydzen commented Jun 2, 2023

0 is a valid timestamp, however, an error occurs during parsing

code example:

from marshmallow import fields, Schema


class A(Schema):
    x = fields.DateTime('timestamp')


a = A().load({"x": 0})
print(a)

expected:

{'x': datetime.datetime(1970, 1, 1, 0, 0)}

actual

marshmallow.exceptions.ValidationError: {'x': ['Not a valid datetime.']}

bug line

@flydzen flydzen changed the title timestamp 0 is not valid for DateTime(format='timestamp') timestamp 0 is not valid for DateTime('timestamp') Jun 2, 2023
@deckar01 deckar01 added the bug label Jun 2, 2023
@deckar01
Copy link
Member

deckar01 commented Jun 2, 2023

It looks like we can safely remove the falsy check in DateTime._deserialize(). Other than a unit test being added to explicitly reject zero timestamps all of the other formats covered by the unit tests continue to reject invalid values with an identical error.

dev...deckar01:marshmallow:2133-zero-timestamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants