Skip to content

Commit b6b72aa

Browse files
committed
addRawRequestMethod: update-changes-requested
1 parent e9c47d9 commit b6b72aa

File tree

5 files changed

+13
-35
lines changed

5 files changed

+13
-35
lines changed

openfga_sdk/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ async def __call_api(
420420
if _return_http_data_only:
421421
return return_data
422422
else:
423-
return (return_data, response_data.status, response_data.getheaders())
423+
return (return_data, response_data.status, response_data.headers)
424424

425425
def _parse_retry_after_header(self, headers) -> int:
426426
retry_after_header = headers.get("retry-after")

openfga_sdk/client/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,15 +1216,15 @@ async def raw_request(
12161216
TelemetryAttributes.fga_client_request_store_id
12171217
] = self.get_store_id()
12181218

1219-
_, http_status, http_headers = await self._api_client.call_api(
1219+
await self._api_client.call_api(
12201220
resource_path=resource_path,
12211221
method=method.upper(),
12221222
query_params=query_params_list if query_params_list else None,
12231223
header_params=auth_headers if auth_headers else None,
12241224
body=body_params,
12251225
response_types_map={},
12261226
auth_settings=[],
1227-
_return_http_data_only=False,
1227+
_return_http_data_only=True,
12281228
_preload_content=True,
12291229
_retry_params=retry_params,
12301230
_oauth2_client=self._api._oauth2_client,
@@ -1262,7 +1262,7 @@ async def raw_request(
12621262
response_body = rest_response.data
12631263

12641264
return RawResponse(
1265-
status=http_status,
1266-
headers=http_headers if http_headers else {},
1265+
status=rest_response.status,
1266+
headers=dict(rest_response.getheaders()),
12671267
body=response_body,
12681268
)

openfga_sdk/client/models/raw_response.py

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from dataclasses import dataclass
99
from typing import Any
10+
import json
1011

1112

1213
@dataclass
@@ -34,34 +35,13 @@ def json(self) -> dict[str, Any] | None:
3435
"""
3536
Return the response body as a JSON dictionary.
3637
37-
If the body is already a dict (parsed JSON), returns it directly.
38-
If the body is a string or bytes, attempts to parse it as JSON.
39-
Returns None if body is None or cannot be parsed.
38+
The body is already parsed during the request, so this typically
39+
just returns the body if it's a dict, or None otherwise.
4040
4141
:return: Parsed JSON dictionary or None
4242
"""
43-
if self.body is None:
44-
return None
45-
4643
if isinstance(self.body, dict):
4744
return self.body
48-
49-
if isinstance(self.body, str):
50-
import json
51-
52-
try:
53-
return json.loads(self.body)
54-
except (json.JSONDecodeError, ValueError):
55-
return None
56-
57-
if isinstance(self.body, bytes):
58-
import json
59-
60-
try:
61-
return json.loads(self.body.decode("utf-8"))
62-
except (json.JSONDecodeError, ValueError, UnicodeDecodeError):
63-
return None
64-
6545
return None
6646

6747
def text(self) -> str | None:
@@ -83,8 +63,6 @@ def text(self) -> str | None:
8363
return self.body.decode("utf-8", errors="replace")
8464

8565
if isinstance(self.body, dict):
86-
import json
87-
8866
return json.dumps(self.body)
8967

9068
return str(self.body)

openfga_sdk/sync/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def __call_api(
420420
if _return_http_data_only:
421421
return return_data
422422
else:
423-
return (return_data, response_data.status, response_data.getheaders())
423+
return (return_data, response_data.status, response_data.headers)
424424

425425
def _parse_retry_after_header(self, headers) -> int:
426426
retry_after_header = headers.get("retry-after")

openfga_sdk/sync/client/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,15 +1215,15 @@ def raw_request(
12151215
TelemetryAttributes.fga_client_request_store_id
12161216
] = self.get_store_id()
12171217

1218-
_, http_status, http_headers = self._api_client.call_api(
1218+
self._api_client.call_api(
12191219
resource_path=resource_path,
12201220
method=method.upper(),
12211221
query_params=query_params_list if query_params_list else None,
12221222
header_params=auth_headers if auth_headers else None,
12231223
body=body_params,
12241224
response_types_map={},
12251225
auth_settings=[],
1226-
_return_http_data_only=False,
1226+
_return_http_data_only=True,
12271227
_preload_content=True,
12281228
_retry_params=retry_params,
12291229
_oauth2_client=self._api._oauth2_client,
@@ -1262,7 +1262,7 @@ def raw_request(
12621262
response_body = rest_response.data
12631263

12641264
return RawResponse(
1265-
status=http_status,
1266-
headers=http_headers if http_headers else {},
1265+
status=rest_response.status,
1266+
headers=dict(rest_response.getheaders()),
12671267
body=response_body,
12681268
)

0 commit comments

Comments
 (0)