Skip to content

Update Gremlin HTTP requests and error handling #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
- Improved iPython config directory retrieval logic ([Link to PR](https://github.com/aws/graph-notebook/pull/687))
- Fixed `%db_reset` output for token modes ([Link to PR](https://github.com/aws/graph-notebook/pull/691))
- Use `extras_require` to specify tests ([Link to PR](https://github.com/aws/graph-notebook/pull/688))
- Updated Gremlin HTTP requests, fixed handling of internal error responses ([Link to PR](https://github.com/aws/graph-notebook/pull/692))

## Release 4.5.2 (August 15, 2024)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pandas>=2.1.0,<=2.2.2
numpy<1.24.0
nest_asyncio>=1.5.5,<=1.5.6
async-timeout>=4.0,<5.0
json-repair==0.29.2

# requirements for testing
botocore~=1.34.74
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def get_version():
'pandas>=2.1.0,<=2.2.2',
'numpy<1.24.0',
'nest_asyncio>=1.5.5,<=1.5.6',
'async-timeout>=4.0,<5.0'
'async-timeout>=4.0,<5.0',
'json-repair==0.29.2'
],
package_data={
'graph_notebook': ['graph_notebook/widgets/nbextensions/**',
Expand Down
7 changes: 6 additions & 1 deletion src/graph_notebook/magics/graph_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from IPython.core.magic import (Magics, magics_class, cell_magic, line_magic, line_cell_magic, needs_local_scope)
from ipywidgets.widgets.widget_description import DescriptionStyle
from requests import HTTPError
from json_repair import repair_json

import graph_notebook
from graph_notebook.configuration.generate_config import generate_default_config, DEFAULT_CONFIG_LOCATION, \
Expand Down Expand Up @@ -1257,7 +1258,11 @@ def gremlin(self, line, cell, local_ns: dict = None):
query_res_http = self.client.gremlin_http_query(cell, headers={
'Accept': 'application/vnd.gremlin-v1.0+json;types=false'})
query_res_http.raise_for_status()
query_res_http_json = query_res_http.json()
try:
query_res_http_json = query_res_http.json()
except JSONDecodeError:
query_res_fixed = repair_json(query_res_http.text)
query_res_http_json = json.loads(query_res_fixed)
query_res = query_res_http_json['result']['data']
else:
query_res = self.client.gremlin_query(cell, transport_args=transport_args)
Expand Down
9 changes: 5 additions & 4 deletions src/graph_notebook/neptune/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ def gremlin_http_query(self, query, headers=None) -> requests.Response:
use_proxy = True if self.proxy_host != '' else False
if self.is_analytics_domain():
uri = f'{self.get_uri(use_websocket=False, use_proxy=use_proxy, include_port=False)}/queries'
data['query'] = query
data['language'] = 'gremlin'
data['gremlin'] = query
headers['content-type'] = 'application/json'
else:
uri = f'{self.get_uri(use_websocket=False, use_proxy=use_proxy)}/gremlin'
Expand Down Expand Up @@ -440,13 +440,14 @@ def _gremlin_query_plan(self, query: str, plan_type: str, args: dict, ) -> reque
url = f'{self._http_protocol}://{self.host}'
if self.is_analytics_domain():
url += '/queries'
data['gremlin'] = query
data['query'] = query
data['language'] = 'gremlin'
headers['content-type'] = 'application/json'
if plan_type == 'explain':
data['explain.mode'] = args.pop('explain.mode')
data['explain-mode'] = args.pop('explain.mode')
elif plan_type == 'profile':
data['profile.debug'] = args.pop('profile.debug')
for param, value in args.items():
data[param] = value
else:
url += f':{self.port}/gremlin/{plan_type}'
data['gremlin'] = query
Expand Down
Loading