Reject booleans in from_timestamp_ms, consistent with from_timestamp#2904
Merged
sloria merged 5 commits intomarshmallow-code:devfrom Mar 25, 2026
Merged
Conversation
from_timestamp explicitly rejects True/False before converting to float, but from_timestamp_ms calls float(value) first, converting booleans to 1.0/0.0 before from_timestamp ever sees them. This means the boolean check in from_timestamp is bypassed. Add the same boolean guard to from_timestamp_ms so that DateTime(format="timestamp_ms") rejects booleans just like DateTime(format="timestamp") does.
24a55ef to
2288b62
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
from_timestamp_msdoesn't reject boolean values, unlikefrom_timestamp. This allowsDateTime(format="timestamp_ms")to silently acceptTrue/Falseas valid timestamps.Problem
from_timestamphas an explicit boolean guard:But
from_timestamp_msconverts to float first:Since
float(True)produces1.0, by the timefrom_timestampis called, the value is already a float and thevalue is Trueidentity check fails. This means:DateTime(format="timestamp")correctly rejectsTrue/FalseDateTime(format="timestamp_ms")silently accepts them, deserializingTrueas a datetimeFix
Add the same boolean rejection to
from_timestamp_msbefore thefloat()conversion.