Skip to content

Commit 958e0b6

Browse files
committed
list correction
1 parent 4836bf9 commit 958e0b6

3 files changed

Lines changed: 66 additions & 10 deletions

File tree

src/workos/_base_client.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,35 @@ def request_raw(
472472
)
473473
return result if isinstance(result, dict) else {}
474474

475+
def request_list(
476+
self,
477+
method: str,
478+
path: str,
479+
*,
480+
params: Optional[Dict[str, Any]] = None,
481+
body: Optional[Dict[str, Any]] = None,
482+
idempotency_key: Optional[str] = None,
483+
request_options: Optional[RequestOptions] = None,
484+
) -> list[Dict[str, Any]]:
485+
"""Make an HTTP request expecting a bare JSON array response.
486+
487+
Returns the raw list of dicts. Use this for endpoints that return
488+
a JSON array instead of a paginated envelope.
489+
"""
490+
result = self.request(
491+
method=method,
492+
path=path,
493+
params=params,
494+
body=body,
495+
idempotency_key=idempotency_key,
496+
request_options=request_options,
497+
)
498+
if not isinstance(result, list):
499+
raise WorkOSError(
500+
f"Expected array response from {method.upper()} /{path}, got {type(result).__name__}"
501+
)
502+
return result
503+
475504
def request_page(
476505
self,
477506
method: str,
@@ -668,6 +697,35 @@ async def request_raw(
668697
)
669698
return result if isinstance(result, dict) else {}
670699

700+
async def request_list(
701+
self,
702+
method: str,
703+
path: str,
704+
*,
705+
params: Optional[Dict[str, Any]] = None,
706+
body: Optional[Dict[str, Any]] = None,
707+
idempotency_key: Optional[str] = None,
708+
request_options: Optional[RequestOptions] = None,
709+
) -> list[Dict[str, Any]]:
710+
"""Make an async HTTP request expecting a bare JSON array response.
711+
712+
Returns the raw list of dicts. Use this for endpoints that return
713+
a JSON array instead of a paginated envelope.
714+
"""
715+
result = await self.request(
716+
method=method,
717+
path=path,
718+
params=params,
719+
body=body,
720+
idempotency_key=idempotency_key,
721+
request_options=request_options,
722+
)
723+
if not isinstance(result, list):
724+
raise WorkOSError(
725+
f"Expected array response from {method.upper()} /{path}, got {type(result).__name__}"
726+
)
727+
return result
728+
671729
async def request_page(
672730
self,
673731
method: str,

src/workos/connect/_resource.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ def list_application_client_secrets(
367367
RateLimitExceededError: If rate limited (429).
368368
ServerError: If the server returns a 5xx error.
369369
"""
370-
raw = self._client.request(
370+
raw = self._client.request_list(
371371
method="get",
372372
path=f"connect/applications/{id}/client_secrets",
373373
request_options=request_options,
374374
)
375375
return [
376376
ApplicationCredentialsListItem.from_dict(cast(Dict[str, Any], item))
377-
for item in (raw if isinstance(raw, list) else [])
377+
for item in raw
378378
]
379379

380380
def create_application_client_secrets(
@@ -781,14 +781,14 @@ async def list_application_client_secrets(
781781
RateLimitExceededError: If rate limited (429).
782782
ServerError: If the server returns a 5xx error.
783783
"""
784-
raw = await self._client.request(
784+
raw = await self._client.request_list(
785785
method="get",
786786
path=f"connect/applications/{id}/client_secrets",
787787
request_options=request_options,
788788
)
789789
return [
790790
ApplicationCredentialsListItem.from_dict(cast(Dict[str, Any], item))
791-
for item in (raw if isinstance(raw, list) else [])
791+
for item in raw
792792
]
793793

794794
async def create_application_client_secrets(

src/workos/user_management/_resource.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,14 +1177,13 @@ def get_user_identities(
11771177
RateLimitExceededError: If rate limited (429).
11781178
ServerError: If the server returns a 5xx error.
11791179
"""
1180-
raw = self._client.request(
1180+
raw = self._client.request_list(
11811181
method="get",
11821182
path=f"user_management/users/{id}/identities",
11831183
request_options=request_options,
11841184
)
11851185
return [
1186-
UserIdentitiesGetItem.from_dict(cast(Dict[str, Any], item))
1187-
for item in (raw if isinstance(raw, list) else [])
1186+
UserIdentitiesGetItem.from_dict(cast(Dict[str, Any], item)) for item in raw
11881187
]
11891188

11901189
def list_sessions(
@@ -3280,14 +3279,13 @@ async def get_user_identities(
32803279
RateLimitExceededError: If rate limited (429).
32813280
ServerError: If the server returns a 5xx error.
32823281
"""
3283-
raw = await self._client.request(
3282+
raw = await self._client.request_list(
32843283
method="get",
32853284
path=f"user_management/users/{id}/identities",
32863285
request_options=request_options,
32873286
)
32883287
return [
3289-
UserIdentitiesGetItem.from_dict(cast(Dict[str, Any], item))
3290-
for item in (raw if isinstance(raw, list) else [])
3288+
UserIdentitiesGetItem.from_dict(cast(Dict[str, Any], item)) for item in raw
32913289
]
32923290

32933291
async def list_sessions(

0 commit comments

Comments
 (0)