Skip to content

Commit 3c2e66a

Browse files
committed
update: handling double-JSON-encodes
1 parent f4dec14 commit 3c2e66a

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

openfga_sdk/client/client.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,23 +1178,20 @@ async def raw_request(
11781178
continue
11791179
query_params_list.append((key, str(value)))
11801180

1181-
body_params = None
1182-
if body is not None:
1183-
if isinstance(body, (dict, list)):
1184-
body_params = json.dumps(body)
1181+
body_params = body
1182+
if "Content-Type" not in request_headers:
1183+
if isinstance(body, (dict, list)) or body is None:
1184+
request_headers["Content-Type"] = "application/json"
11851185
elif isinstance(body, str):
1186-
body_params = body
1186+
request_headers["Content-Type"] = "text/plain"
11871187
elif isinstance(body, bytes):
1188-
body_params = body
1188+
request_headers["Content-Type"] = "application/octet-stream"
11891189
else:
1190-
body_params = json.dumps(body)
1190+
request_headers["Content-Type"] = "application/json"
11911191

11921192
retry_params = None
11931193
if options and options.get("retry_params"):
11941194
retry_params = options["retry_params"]
1195-
1196-
if "Content-Type" not in request_headers:
1197-
request_headers["Content-Type"] = "application/json"
11981195
if "Accept" not in request_headers:
11991196
request_headers["Accept"] = "application/json"
12001197

openfga_sdk/sync/client/client.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,23 +1178,20 @@ def raw_request(
11781178
continue
11791179
query_params_list.append((key, str(value)))
11801180

1181-
body_params = None
1182-
if body is not None:
1183-
if isinstance(body, (dict, list)):
1184-
body_params = json.dumps(body)
1181+
body_params = body
1182+
if "Content-Type" not in request_headers:
1183+
if isinstance(body, (dict, list)) or body is None:
1184+
request_headers["Content-Type"] = "application/json"
11851185
elif isinstance(body, str):
1186-
body_params = body
1186+
request_headers["Content-Type"] = "text/plain"
11871187
elif isinstance(body, bytes):
1188-
body_params = body
1188+
request_headers["Content-Type"] = "application/octet-stream"
11891189
else:
1190-
body_params = json.dumps(body)
1190+
request_headers["Content-Type"] = "application/json"
11911191

11921192
retry_params = None
11931193
if options and options.get("retry_params"):
11941194
retry_params = options["retry_params"]
1195-
1196-
if "Content-Type" not in request_headers:
1197-
request_headers["Content-Type"] = "application/json"
11981195
if "Accept" not in request_headers:
11991196
request_headers["Accept"] = "application/json"
12001197

0 commit comments

Comments
 (0)