Skip to content

Commit 4511645

Browse files
Reject float timestamp coercion in session model
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 4e7aab0 commit 4511645

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

hyperbrowser/models/session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ def parse_timestamp(cls, value: Optional[Union[str, int]]) -> Optional[int]:
163163
) from exc
164164
if isinstance(value, str):
165165
raise ValueError("timestamp string values must be plain strings")
166-
return value
166+
raise ValueError(
167+
"timestamp values must be plain integers or plain numeric strings"
168+
)
167169

168170

169171
class SessionDetail(Session):

tests/test_session_models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,14 @@ def test_session_model_rejects_non_integer_timestamp_strings():
8484
ValidationError, match="timestamp string values must be integer-formatted"
8585
):
8686
Session.model_validate(payload)
87+
88+
89+
def test_session_model_rejects_float_timestamps():
90+
payload = _build_session_payload()
91+
payload["startTime"] = 1.0
92+
93+
with pytest.raises(
94+
ValidationError,
95+
match="timestamp values must be plain integers or plain numeric strings",
96+
):
97+
Session.model_validate(payload)

0 commit comments

Comments
 (0)