Skip to content

Commit 9ff6150

Browse files
committed
CUST-5289 [v3] Python SDK ListGrantsQueryParams uses camelCase keys that are silently ignored by the API
License I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner. Fix ListGrantsQueryParams key handling in Python SDK - Fix bug where `sortBy`, `orderBy`, and `grantStatus` are sent as-is and ignored by the API. - Normalize grants query aliases to `sort_by`, `order_by`, and `grant_status` at request serialization time. - Align type hints with snake_case API contract while keeping camelCase aliases for backwards compatibility. - Preserve existing SDK behavior for callers already using snake_case keys. ✅ Tests checks: - `pytest tests/handler/test_http_client.py -k test_build_query_params -q` (100%) - Manual serialization check for grants aliases via `_build_query_params` (verified) Made-with: Cursor
1 parent c15faa5 commit 9ff6150

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

nylas/handler/http_client.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,22 @@ def _validate_response(response: Response) -> Tuple[Dict, CaseInsensitiveDict]:
4949

5050
def _build_query_params(base_url: str, query_params: dict = None) -> str:
5151
query_param_parts = []
52+
query_param_key_aliases = {
53+
"sortBy": "sort_by",
54+
"orderBy": "order_by",
55+
"grantStatus": "grant_status",
56+
}
57+
5258
for key, value in query_params.items():
59+
normalized_key = query_param_key_aliases.get(key, key)
5360
if isinstance(value, list):
5461
for item in value:
55-
query_param_parts.append(f"{key}={quote(str(item))}")
62+
query_param_parts.append(f"{normalized_key}={quote(str(item))}")
5663
elif isinstance(value, dict):
5764
for k, v in value.items():
58-
query_param_parts.append(f"{key}={k}:{quote(str(v))}")
65+
query_param_parts.append(f"{normalized_key}={k}:{quote(str(v))}")
5966
else:
60-
query_param_parts.append(f"{key}={quote(str(value))}")
67+
query_param_parts.append(f"{normalized_key}={quote(str(value))}")
6168

6269
query_string = "&".join(query_param_parts)
6370
return f"{base_url}?{query_string}"

nylas/models/grants.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,30 @@ class ListGrantsQueryParams(TypedDict):
8383
limit: The maximum number of objects to return.
8484
This field defaults to 10. The maximum allowed value is 200.
8585
offset: Offset grant results by this number.
86-
sortBy: Sort entries by field name
87-
orderBy: Specify ascending or descending order.
86+
sort_by: Sort entries by field name.
87+
order_by: Specify ascending or descending order.
8888
since: Scope grants from a specific point in time by Unix timestamp.
8989
before: Scope grants to a specific point in time by Unix timestamp.
9090
email: Filtering your query based on grant email address (if applicable)
91-
grantStatus: Filtering your query based on grant email status (if applicable)
91+
grant_status: Filtering your query based on grant email status (if applicable)
9292
ip: Filtering your query based on grant IP address
9393
provider: Filtering your query based on OAuth provider
94+
sortBy: Deprecated camelCase alias for sort_by.
95+
orderBy: Deprecated camelCase alias for order_by.
96+
grantStatus: Deprecated camelCase alias for grant_status.
9497
"""
9598

9699
limit: NotRequired[int]
97100
offset: NotRequired[int]
98-
sortBy: NotRequired[str]
99-
orderBy: NotRequired[str]
101+
sort_by: NotRequired[str]
102+
order_by: NotRequired[str]
100103
since: NotRequired[int]
101104
before: NotRequired[int]
102105
email: NotRequired[str]
103-
grantStatus: NotRequired[str]
106+
grant_status: NotRequired[str]
104107
ip: NotRequired[str]
105108
provider: NotRequired[Provider]
109+
# Backward-compatible aliases for callers still passing camelCase keys.
110+
sortBy: NotRequired[str]
111+
orderBy: NotRequired[str]
112+
grantStatus: NotRequired[str]

0 commit comments

Comments
 (0)