diff --git a/src/marshmallow/fields.py b/src/marshmallow/fields.py index ceb32aa91..3d3bec961 100644 --- a/src/marshmallow/fields.py +++ b/src/marshmallow/fields.py @@ -1285,6 +1285,8 @@ 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/tests/test_deserialization.py b/tests/test_deserialization.py index 4588e2a7d..442b5efbd 100644 --- a/tests/test_deserialization.py +++ b/tests/test_deserialization.py @@ -422,6 +422,8 @@ def test_field_toggle_show_invalid_value_in_error_message(self): [ "not-a-datetime", 42, + True, + False, 0, "", [],