Skip to content

Commit

Permalink
DateTime field: allow timestamp 0
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Apr 30, 2024
1 parent 183c411 commit 845f573
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/marshmallow/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,8 +1285,6 @@ def _serialize(self, value, attr, obj, **kwargs) -> str | float | None:
return value.strftime(data_format)

def _deserialize(self, value, attr, data, **kwargs) -> dt.datetime:
if not value: # Falsy values, e.g. '', None, [] are not valid
raise self.make_error("invalid", input=value, obj_type=self.OBJ_TYPE)
data_format = self.format or self.DEFAULT_FORMAT
func = self.DESERIALIZATION_FUNCS.get(data_format)
try:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def test_field_toggle_show_invalid_value_in_error_message(self):
[
"not-a-datetime",
42,
0,
"",
[],
"2018",
Expand Down Expand Up @@ -576,7 +577,7 @@ def test_timestamp_field_deserialization(self, fmt, value, expected):
@pytest.mark.parametrize("fmt", ["timestamp", "timestamp_ms"])
@pytest.mark.parametrize(
"in_value",
["", "!@#", 0, -1, dt.datetime(2013, 11, 10, 1, 23, 45)],
["", "!@#", -1, dt.datetime(2013, 11, 10, 1, 23, 45)],
)
def test_invalid_timestamp_field_deserialization(self, fmt, in_value):
field = fields.DateTime(format=fmt)
Expand Down

0 comments on commit 845f573

Please sign in to comment.