Skip to content

Commit 4e912f6

Browse files
Reject int-subclass session timestamp values
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent ede7d0c commit 4e912f6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

hyperbrowser/models/session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ def parse_timestamp(cls, value: Optional[Union[str, int]]) -> Optional[int]:
148148
raise ValueError(
149149
"timestamp values must be integers or plain numeric strings"
150150
)
151+
if type(value) is int:
152+
return value
153+
if isinstance(value, int):
154+
raise ValueError(
155+
"timestamp values must be plain integers or plain numeric strings"
156+
)
151157
if type(value) is str:
152158
try:
153159
return int(value)

tests/test_session_models.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ def test_session_model_preserves_integer_timestamps():
6262
assert model.end_time == 1735689660
6363

6464

65+
def test_session_model_rejects_integer_subclass_timestamps():
66+
class _TimestampInt(int):
67+
pass
68+
69+
payload = _build_session_payload()
70+
payload["startTime"] = _TimestampInt(1735689600)
71+
72+
with pytest.raises(
73+
ValidationError,
74+
match="timestamp values must be plain integers or plain numeric strings",
75+
):
76+
Session.model_validate(payload)
77+
78+
6579
def test_session_model_rejects_non_integer_timestamp_strings():
6680
payload = _build_session_payload()
6781
payload["startTime"] = "not-a-number"

0 commit comments

Comments
 (0)