Skip to content

Commit 3f85dfa

Browse files
committed
addRawRequestMethod: fix testcases & remove trailing spaces
1 parent 3c2e66a commit 3f85dfa

File tree

6 files changed

+156
-113
lines changed

6 files changed

+156
-113
lines changed

openfga_sdk/client/client.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import asyncio
2-
import uuid
2+
import json
33
import urllib.parse
4+
import uuid
5+
46
from typing import Any
5-
import json
67

78
from openfga_sdk.api.open_fga_api import OpenFgaApi
89
from openfga_sdk.api_client import ApiClient
@@ -28,6 +29,7 @@
2829
from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest
2930
from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest
3031
from openfga_sdk.client.models.list_users_request import ClientListUsersRequest
32+
from openfga_sdk.client.models.raw_response import RawResponse
3133
from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest
3234
from openfga_sdk.client.models.tuple import ClientTuple, convert_tuple_keys
3335
from openfga_sdk.client.models.write_request import ClientWriteRequest
@@ -36,15 +38,13 @@
3638
construct_write_single_response,
3739
)
3840
from openfga_sdk.client.models.write_transaction_opts import WriteTransactionOpts
39-
from openfga_sdk.client.models.raw_response import RawResponse
4041
from openfga_sdk.constants import (
4142
CLIENT_BULK_REQUEST_ID_HEADER,
4243
CLIENT_MAX_BATCH_SIZE,
4344
CLIENT_MAX_METHOD_PARALLEL_REQUESTS,
4445
CLIENT_METHOD_HEADER,
4546
)
4647
from openfga_sdk.exceptions import (
47-
ApiException,
4848
AuthenticationError,
4949
FgaValidationException,
5050
UnauthorizedException,
@@ -72,8 +72,11 @@
7272
WriteAuthorizationModelRequest,
7373
)
7474
from openfga_sdk.models.write_request import WriteRequest
75-
from openfga_sdk.validation import is_well_formed_ulid_string
7675
from openfga_sdk.rest import RESTResponse
76+
from openfga_sdk.telemetry.attributes import (
77+
TelemetryAttributes,
78+
)
79+
from openfga_sdk.validation import is_well_formed_ulid_string
7780

7881

7982
def _chuck_array(array, max_size):
@@ -1146,7 +1149,7 @@ async def raw_request(
11461149

11471150
resource_path = path
11481151
path_params_dict = dict(path_params) if path_params else {}
1149-
1152+
11501153
if "{store_id}" in resource_path and "store_id" not in path_params_dict:
11511154
store_id = self.get_store_id()
11521155
if store_id is None or store_id == "":
@@ -1155,7 +1158,7 @@ async def raw_request(
11551158
"Set store_id in ClientConfiguration, use set_store_id(), or provide it in path_params."
11561159
)
11571160
path_params_dict["store_id"] = store_id
1158-
1161+
11591162
for param_name, param_value in path_params_dict.items():
11601163
placeholder = f"{{{param_name}}}"
11611164
if placeholder in resource_path:
@@ -1205,36 +1208,39 @@ async def raw_request(
12051208

12061209
telemetry_attributes = None
12071210
if operation_name:
1208-
from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes
12091211
telemetry_attributes = {
12101212
TelemetryAttributes.fga_client_request_method: operation_name.lower(),
12111213
}
12121214
if self.get_store_id():
1213-
telemetry_attributes[TelemetryAttributes.fga_client_request_store_id] = self.get_store_id()
1214-
1215-
try:
1216-
_, http_status, http_headers = await self._api_client.call_api(
1217-
resource_path=resource_path,
1218-
method=method.upper(),
1219-
query_params=query_params_list if query_params_list else None,
1220-
header_params=auth_headers if auth_headers else None,
1221-
body=body_params,
1222-
response_types_map={},
1223-
auth_settings=[],
1224-
_return_http_data_only=False,
1225-
_preload_content=True,
1226-
_retry_params=retry_params,
1227-
_oauth2_client=self._api._oauth2_client,
1228-
_telemetry_attributes=telemetry_attributes,
1229-
)
1230-
except ApiException as e:
1231-
raise
1215+
telemetry_attributes[
1216+
TelemetryAttributes.fga_client_request_store_id
1217+
] = self.get_store_id()
1218+
1219+
_, http_status, http_headers = await self._api_client.call_api(
1220+
resource_path=resource_path,
1221+
method=method.upper(),
1222+
query_params=query_params_list if query_params_list else None,
1223+
header_params=auth_headers if auth_headers else None,
1224+
body=body_params,
1225+
response_types_map={},
1226+
auth_settings=[],
1227+
_return_http_data_only=False,
1228+
_preload_content=True,
1229+
_retry_params=retry_params,
1230+
_oauth2_client=self._api._oauth2_client,
1231+
_telemetry_attributes=telemetry_attributes,
1232+
)
12321233
rest_response: RESTResponse | None = getattr(
12331234
self._api_client, "last_response", None
12341235
)
12351236

12361237
if rest_response is None:
1237-
raise RuntimeError("Failed to get response from API client")
1238+
raise RuntimeError(
1239+
f"Failed to get response from API client for {method.upper()} "
1240+
f"request to '{resource_path}'"
1241+
f"{f' (operation: {operation_name})' if operation_name else ''}. "
1242+
"This may indicate an internal SDK error, network problem, or client configuration issue."
1243+
)
12381244

12391245
response_body: bytes | str | dict[str, Any] | None = None
12401246
if rest_response.data is not None:

openfga_sdk/client/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from openfga_sdk.client.models.expand_request import ClientExpandRequest
1313
from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest
1414
from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest
15+
from openfga_sdk.client.models.raw_response import RawResponse
1516
from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest
1617
from openfga_sdk.client.models.tuple import ClientTuple
1718
from openfga_sdk.client.models.write_conflict_opts import (
@@ -23,7 +24,6 @@
2324
from openfga_sdk.client.models.write_request import ClientWriteRequest
2425
from openfga_sdk.client.models.write_response import ClientWriteResponse
2526
from openfga_sdk.client.models.write_transaction_opts import WriteTransactionOpts
26-
from openfga_sdk.client.models.raw_response import RawResponse
2727

2828

2929
__all__ = [

openfga_sdk/client/models/raw_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class RawResponse:
2323

2424
status: int
2525
"""HTTP status code"""
26-
26+
2727
headers: dict[str, str]
2828
"""Response headers as a dictionary"""
29-
29+
3030
body: bytes | str | dict[str, Any] | None = None
3131
"""Response body (already parsed as dict if JSON, otherwise str or bytes)"""
3232

openfga_sdk/sync/client/client.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import uuid
21
import json
32
import urllib.parse
4-
from typing import Any
3+
import uuid
54

65
from concurrent.futures import ThreadPoolExecutor
6+
from typing import Any
77

88
from openfga_sdk.client.configuration import ClientConfiguration
99
from openfga_sdk.client.models.assertion import ClientAssertion
@@ -27,6 +27,7 @@
2727
from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest
2828
from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest
2929
from openfga_sdk.client.models.list_users_request import ClientListUsersRequest
30+
from openfga_sdk.client.models.raw_response import RawResponse
3031
from openfga_sdk.client.models.read_changes_request import ClientReadChangesRequest
3132
from openfga_sdk.client.models.tuple import ClientTuple, convert_tuple_keys
3233
from openfga_sdk.client.models.write_request import ClientWriteRequest
@@ -35,15 +36,13 @@
3536
construct_write_single_response,
3637
)
3738
from openfga_sdk.client.models.write_transaction_opts import WriteTransactionOpts
38-
from openfga_sdk.client.models.raw_response import RawResponse
3939
from openfga_sdk.constants import (
4040
CLIENT_BULK_REQUEST_ID_HEADER,
4141
CLIENT_MAX_BATCH_SIZE,
4242
CLIENT_MAX_METHOD_PARALLEL_REQUESTS,
4343
CLIENT_METHOD_HEADER,
4444
)
4545
from openfga_sdk.exceptions import (
46-
ApiException,
4746
AuthenticationError,
4847
FgaValidationException,
4948
UnauthorizedException,
@@ -73,8 +72,11 @@
7372
from openfga_sdk.models.write_request import WriteRequest
7473
from openfga_sdk.sync.api_client import ApiClient
7574
from openfga_sdk.sync.open_fga_api import OpenFgaApi
76-
from openfga_sdk.validation import is_well_formed_ulid_string
7775
from openfga_sdk.sync.rest import RESTResponse
76+
from openfga_sdk.telemetry.attributes import (
77+
TelemetryAttributes,
78+
)
79+
from openfga_sdk.validation import is_well_formed_ulid_string
7880

7981

8082
def _chuck_array(array, max_size):
@@ -1145,7 +1147,7 @@ def raw_request(
11451147

11461148
resource_path = path
11471149
path_params_dict = dict(path_params) if path_params else {}
1148-
1150+
11491151
if "{store_id}" in resource_path and "store_id" not in path_params_dict:
11501152
store_id = self.get_store_id()
11511153
if store_id is None or store_id == "":
@@ -1154,13 +1156,13 @@ def raw_request(
11541156
"Set store_id in ClientConfiguration, use set_store_id(), or provide it in path_params."
11551157
)
11561158
path_params_dict["store_id"] = store_id
1157-
1159+
11581160
for param_name, param_value in path_params_dict.items():
11591161
placeholder = f"{{{param_name}}}"
11601162
if placeholder in resource_path:
11611163
encoded_value = urllib.parse.quote(str(param_value), safe="")
11621164
resource_path = resource_path.replace(placeholder, encoded_value)
1163-
1165+
11641166
if "{" in resource_path or "}" in resource_path:
11651167
raise FgaValidationException(
11661168
f"Not all path parameters were provided for path: {path}"
@@ -1205,37 +1207,40 @@ def raw_request(
12051207

12061208
telemetry_attributes = None
12071209
if operation_name:
1208-
from openfga_sdk.telemetry.attributes import TelemetryAttribute, TelemetryAttributes
12091210
telemetry_attributes = {
12101211
TelemetryAttributes.fga_client_request_method: operation_name.lower(),
12111212
}
12121213
if self.get_store_id():
1213-
telemetry_attributes[TelemetryAttributes.fga_client_request_store_id] = self.get_store_id()
1214-
1215-
try:
1216-
_, http_status, http_headers = self._api_client.call_api(
1217-
resource_path=resource_path,
1218-
method=method.upper(),
1219-
query_params=query_params_list if query_params_list else None,
1220-
header_params=auth_headers if auth_headers else None,
1221-
body=body_params,
1222-
response_types_map={},
1223-
auth_settings=[],
1224-
_return_http_data_only=False,
1225-
_preload_content=True,
1226-
_retry_params=retry_params,
1227-
_oauth2_client=self._api._oauth2_client,
1228-
_telemetry_attributes=telemetry_attributes,
1229-
)
1230-
except ApiException as e:
1231-
raise
1214+
telemetry_attributes[
1215+
TelemetryAttributes.fga_client_request_store_id
1216+
] = self.get_store_id()
1217+
1218+
_, http_status, http_headers = self._api_client.call_api(
1219+
resource_path=resource_path,
1220+
method=method.upper(),
1221+
query_params=query_params_list if query_params_list else None,
1222+
header_params=auth_headers if auth_headers else None,
1223+
body=body_params,
1224+
response_types_map={},
1225+
auth_settings=[],
1226+
_return_http_data_only=False,
1227+
_preload_content=True,
1228+
_retry_params=retry_params,
1229+
_oauth2_client=self._api._oauth2_client,
1230+
_telemetry_attributes=telemetry_attributes,
1231+
)
12321232

12331233
rest_response: RESTResponse | None = getattr(
12341234
self._api_client, "last_response", None
12351235
)
12361236

12371237
if rest_response is None:
1238-
raise RuntimeError("Failed to get response from API client")
1238+
raise RuntimeError(
1239+
f"Failed to get response from API client for {method.upper()} "
1240+
f"request to '{resource_path}'"
1241+
f"{f' (operation: {operation_name})' if operation_name else ''}. "
1242+
"This may indicate an internal SDK error, network problem, or client configuration issue."
1243+
)
12391244

12401245
response_body: bytes | str | dict[str, Any] | None = None
12411246
if rest_response.data is not None:

0 commit comments

Comments
 (0)