From 58fbbcd3446ade39ea3be83ce9ee9170acf0230b Mon Sep 17 00:00:00 2001 From: Jared Deckard Date: Wed, 1 May 2024 17:38:13 +0200 Subject: [PATCH] Encapsulate timestamp boolean check in utils --- src/marshmallow/fields.py | 2 -- src/marshmallow/utils.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/marshmallow/fields.py b/src/marshmallow/fields.py index 3d3bec961..ceb32aa91 100644 --- a/src/marshmallow/fields.py +++ b/src/marshmallow/fields.py @@ -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 value is True or value is False: - 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: diff --git a/src/marshmallow/utils.py b/src/marshmallow/utils.py index 1194bb3a7..a5fe72624 100644 --- a/src/marshmallow/utils.py +++ b/src/marshmallow/utils.py @@ -192,6 +192,8 @@ def from_iso_date(value): def from_timestamp(value: typing.Any) -> dt.datetime: + if value is True or value is False: + raise ValueError("Not a valid POSIX timestamp") value = float(value) if value < 0: raise ValueError("Not a valid POSIX timestamp")