Skip to content

Commit 7c597e6

Browse files
Merge pull request #70 from tigergraph/empty-set-fix
fix(runInstalledQuery): change behavior to handle empty sets in v3.8
2 parents bf429c0 + ecdbdbe commit 7c597e6

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

pyTigerGraph/pyTigerGraphBase.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def _errorCheck(self, res: dict):
207207

208208
def _req(self, method: str, url: str, authMode: str = "token", headers: dict = None,
209209
data: Union[dict, list, str] = None, resKey: str = "results", skipCheck: bool = False,
210-
params: Union[dict, list, str] = None, strictJson: bool = True) -> Union[dict, list]:
210+
params: Union[dict, list, str] = None, strictJson: bool = True, jsonData: bool = False) -> Union[dict, list]:
211211
"""Generic REST++ API request.
212212
213213
Args:
@@ -228,6 +228,10 @@ def _req(self, method: str, url: str, authMode: str = "token", headers: dict = N
228228
action is not applicable. This argument skips error checking.
229229
params:
230230
Request URL parameters.
231+
strictJson:
232+
If JSON should load the response in strict mode or not.
233+
jsonData:
234+
If data in data var is a JSON document.
231235
232236
Returns:
233237
The (relevant part of the) response from the request (as a dictionary).
@@ -258,10 +262,14 @@ def _req(self, method: str, url: str, authMode: str = "token", headers: dict = N
258262
_data = None
259263

260264
if self.useCert is True or self.certPath is not None:
261-
res = requests.request(method, url, headers=_headers, data=_data, params=params,
262-
verify=False)
265+
verify = False
263266
else:
264-
res = requests.request(method, url, headers=_headers, data=_data, params=params)
267+
verify = True
268+
269+
if jsonData:
270+
res = requests.request(method, url, headers=_headers, json=_data, params=params, verify=verify)
271+
else:
272+
res = requests.request(method, url, headers=_headers, data=_data, params=params, verify=verify)
265273

266274
if res.status_code != 200:
267275
res.raise_for_status()
@@ -317,7 +325,7 @@ def _get(self, url: str, authMode: str = "token", headers: dict = None, resKey:
317325

318326
def _post(self, url: str, authMode: str = "token", headers: dict = None,
319327
data: Union[dict, list, str, bytes] = None, resKey: str = "results", skipCheck: bool = False,
320-
params: Union[dict, list, str] = None) -> Union[dict, list]:
328+
params: Union[dict, list, str] = None, jsonData: bool = False) -> Union[dict, list]:
321329
"""Generic POST method.
322330
323331
Args:
@@ -344,7 +352,7 @@ def _post(self, url: str, authMode: str = "token", headers: dict = None,
344352
if logger.level == logging.DEBUG:
345353
logger.debug("params: " + self._locals(locals()))
346354

347-
res = self._req("POST", url, authMode, headers, data, resKey, skipCheck, params)
355+
res = self._req("POST", url, authMode, headers, data, resKey, skipCheck, params, jsonData=jsonData)
348356

349357
if logger.level == logging.DEBUG:
350358
logger.debug("return: " + str(res))

pyTigerGraph/pyTigerGraphQuery.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _parseQueryParameters(self, params: dict) -> str:
125125
return ret
126126

127127
def runInstalledQuery(self, queryName: str, params: Union[str, dict] = None,
128-
timeout: int = None, sizeLimit: int = None, usePost: bool = False, runAsync: bool = False,
128+
timeout: int = None, sizeLimit: int = None, usePost: bool = True, runAsync: bool = False,
129129
replica: int = None, threadLimit: int = None) -> list:
130130
"""Runs an installed query.
131131
@@ -146,8 +146,9 @@ def runInstalledQuery(self, queryName: str, params: Union[str, dict] = None,
146146
Maximum size of response (in bytes).
147147
See xref:tigergraph-server:API:index.adoc#_response_size[Response size]
148148
usePost:
149-
The RESTPP accepts a maximum URL length of 8192 characters. Use POST if additional parameters cause
150-
you to exceed this limit.
149+
Defaults to True. The RESTPP accepts a maximum URL length of 8192 characters.
150+
Use POST if additional parameters cause you to exceed this limit. You cannot pass
151+
empty sets as parameters if usePost is False.
151152
runAsync:
152153
Run the query in asynchronous mode.
153154
See xref:gsql-ref:querying:query-operations#_detached_mode_async_option[Async operation]
@@ -201,21 +202,20 @@ def runInstalledQuery(self, queryName: str, params: Union[str, dict] = None,
201202
if replica:
202203
headers["GSQL-REPLICA"] = str(replica)
203204
if threadLimit:
204-
headers["GSQL-THREAD-LIMIT"] = str(threadLimit)
205-
206-
if isinstance(params, dict):
207-
params = self._parseQueryParameters(params)
205+
headers["GSQL-THREAD-LIMIT"] = str(threadLimit)
208206

209207
if usePost:
210208
ret = self._post(self.restppUrl + "/query/" + self.graphname + "/" + queryName,
211-
data=params, headers=headers, resKey=res_key)
209+
data=params, headers=headers, resKey=res_key, jsonData=True)
212210

213211
if logger.level == logging.DEBUG:
214212
logger.debug("return: " + str(ret))
215213
logger.info("exit: runInstalledQuery (POST)")
216214

217215
return ret
218216
else:
217+
if isinstance(params, dict):
218+
params = self._parseQueryParameters(params)
219219
ret = self._get(self.restppUrl + "/query/" + self.graphname + "/" + queryName,
220220
params=params, headers=headers, resKey=res_key)
221221

0 commit comments

Comments
 (0)