Skip to content

Commit f1a97f8

Browse files
Require plain UpdateSessionProfileParams in session managers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 66763e8 commit f1a97f8

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

hyperbrowser/client/managers/async_manager/session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,16 @@ async def update_profile_params(
247247
) -> BasicResponse:
248248
params_obj: UpdateSessionProfileParams
249249

250-
if isinstance(params, UpdateSessionProfileParams):
250+
if type(params) is UpdateSessionProfileParams:
251251
if persist_changes is not None:
252252
raise HyperbrowserError(
253253
"Pass either UpdateSessionProfileParams as the second argument or persist_changes=bool, not both."
254254
)
255255
params_obj = params
256+
elif isinstance(params, UpdateSessionProfileParams):
257+
raise HyperbrowserError(
258+
"update_profile_params() requires a plain UpdateSessionProfileParams object."
259+
)
256260
elif isinstance(params, bool):
257261
if persist_changes is not None:
258262
raise HyperbrowserError(

hyperbrowser/client/managers/sync_manager/session.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,16 @@ def update_profile_params(
239239
) -> BasicResponse:
240240
params_obj: UpdateSessionProfileParams
241241

242-
if isinstance(params, UpdateSessionProfileParams):
242+
if type(params) is UpdateSessionProfileParams:
243243
if persist_changes is not None:
244244
raise HyperbrowserError(
245245
"Pass either UpdateSessionProfileParams as the second argument or persist_changes=bool, not both."
246246
)
247247
params_obj = params
248+
elif isinstance(params, UpdateSessionProfileParams):
249+
raise HyperbrowserError(
250+
"update_profile_params() requires a plain UpdateSessionProfileParams object."
251+
)
248252
elif isinstance(params, bool):
249253
if persist_changes is not None:
250254
raise HyperbrowserError(

tests/test_session_update_profile_params.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ def test_sync_update_profile_params_rejects_conflicting_arguments():
9595
)
9696

9797

98+
def test_sync_update_profile_params_rejects_subclass_params():
99+
class _Params(UpdateSessionProfileParams):
100+
pass
101+
102+
manager = SyncSessionManager(_SyncClient())
103+
104+
with pytest.raises(HyperbrowserError, match="plain UpdateSessionProfileParams"):
105+
manager.update_profile_params("session-1", _Params(persist_changes=True))
106+
107+
98108
def test_async_update_profile_params_bool_warns_and_serializes():
99109
AsyncSessionManager._has_warned_update_profile_params_boolean_deprecated = False
100110
client = _AsyncClient()
@@ -138,6 +148,22 @@ async def run() -> None:
138148
asyncio.run(run())
139149

140150

151+
def test_async_update_profile_params_rejects_subclass_params():
152+
class _Params(UpdateSessionProfileParams):
153+
pass
154+
155+
manager = AsyncSessionManager(_AsyncClient())
156+
157+
async def run() -> None:
158+
with pytest.raises(HyperbrowserError, match="plain UpdateSessionProfileParams"):
159+
await manager.update_profile_params(
160+
"session-1",
161+
_Params(persist_changes=True),
162+
)
163+
164+
asyncio.run(run())
165+
166+
141167
def test_sync_update_profile_params_requires_argument_or_keyword():
142168
manager = SyncSessionManager(_SyncClient())
143169

0 commit comments

Comments
 (0)