Skip to content

Commit 077c118

Browse files
authored
Update Gremlin HTTP requests and error handling (#692)
* Update Gremlin HTTP requests and error handling * update changelog
1 parent 5cd4830 commit 077c118

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
1111
- Improved iPython config directory retrieval logic ([Link to PR](https://github.com/aws/graph-notebook/pull/687))
1212
- Fixed `%db_reset` output for token modes ([Link to PR](https://github.com/aws/graph-notebook/pull/691))
1313
- Use `extras_require` to specify tests ([Link to PR](https://github.com/aws/graph-notebook/pull/688))
14+
- Updated Gremlin HTTP requests, fixed handling of internal error responses ([Link to PR](https://github.com/aws/graph-notebook/pull/692))
1415

1516
## Release 4.5.2 (August 15, 2024)
1617

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pandas>=2.1.0,<=2.2.2
2424
numpy<1.24.0
2525
nest_asyncio>=1.5.5,<=1.5.6
2626
async-timeout>=4.0,<5.0
27+
json-repair==0.29.2
2728

2829
# requirements for testing
2930
botocore~=1.34.74

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ def get_version():
9191
'pandas>=2.1.0,<=2.2.2',
9292
'numpy<1.24.0',
9393
'nest_asyncio>=1.5.5,<=1.5.6',
94-
'async-timeout>=4.0,<5.0'
94+
'async-timeout>=4.0,<5.0',
95+
'json-repair==0.29.2'
9596
],
9697
package_data={
9798
'graph_notebook': ['graph_notebook/widgets/nbextensions/**',

src/graph_notebook/magics/graph_magic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from IPython.core.magic import (Magics, magics_class, cell_magic, line_magic, line_cell_magic, needs_local_scope)
3737
from ipywidgets.widgets.widget_description import DescriptionStyle
3838
from requests import HTTPError
39+
from json_repair import repair_json
3940

4041
import graph_notebook
4142
from graph_notebook.configuration.generate_config import generate_default_config, DEFAULT_CONFIG_LOCATION, \
@@ -1257,7 +1258,11 @@ def gremlin(self, line, cell, local_ns: dict = None):
12571258
query_res_http = self.client.gremlin_http_query(cell, headers={
12581259
'Accept': 'application/vnd.gremlin-v1.0+json;types=false'})
12591260
query_res_http.raise_for_status()
1260-
query_res_http_json = query_res_http.json()
1261+
try:
1262+
query_res_http_json = query_res_http.json()
1263+
except JSONDecodeError:
1264+
query_res_fixed = repair_json(query_res_http.text)
1265+
query_res_http_json = json.loads(query_res_fixed)
12611266
query_res = query_res_http_json['result']['data']
12621267
else:
12631268
query_res = self.client.gremlin_query(cell, transport_args=transport_args)

src/graph_notebook/neptune/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ def gremlin_http_query(self, query, headers=None) -> requests.Response:
406406
use_proxy = True if self.proxy_host != '' else False
407407
if self.is_analytics_domain():
408408
uri = f'{self.get_uri(use_websocket=False, use_proxy=use_proxy, include_port=False)}/queries'
409+
data['query'] = query
409410
data['language'] = 'gremlin'
410-
data['gremlin'] = query
411411
headers['content-type'] = 'application/json'
412412
else:
413413
uri = f'{self.get_uri(use_websocket=False, use_proxy=use_proxy)}/gremlin'
@@ -440,13 +440,14 @@ def _gremlin_query_plan(self, query: str, plan_type: str, args: dict, ) -> reque
440440
url = f'{self._http_protocol}://{self.host}'
441441
if self.is_analytics_domain():
442442
url += '/queries'
443-
data['gremlin'] = query
443+
data['query'] = query
444444
data['language'] = 'gremlin'
445445
headers['content-type'] = 'application/json'
446446
if plan_type == 'explain':
447-
data['explain.mode'] = args.pop('explain.mode')
447+
data['explain-mode'] = args.pop('explain.mode')
448448
elif plan_type == 'profile':
449-
data['profile.debug'] = args.pop('profile.debug')
449+
for param, value in args.items():
450+
data[param] = value
450451
else:
451452
url += f':{self.port}/gremlin/{plan_type}'
452453
data['gremlin'] = query

0 commit comments

Comments
 (0)