Skip to content

Add redirect messaging for service-restricted Neptune magics #643

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
Jul 13, 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 @@ -8,6 +8,7 @@ Starting with v1.31.6, this file will contain a record of major features and upd
- Path: 01-Neptune-Database > 03-Sample-Applications > 07-Games-Industry-Graphs
- Added `--connected-table` option to magics with table widget output ([Link to PR](https://github.com/aws/graph-notebook/pull/634))
- Added `--silent` option to the `%%graph_notebook_config` line and cell magics ([Link to PR](https://github.com/aws/graph-notebook/pull/641))
- Added helpful redirect messaging for service-specific Neptune magics ([Link to PR](https://github.com/aws/graph-notebook/pull/643))
- Changed `%%gremlin --store-to` to also store exceptions from non-Neptune queries ([Link to PR](https://github.com/aws/graph-notebook/pull/635))
- Fixed broken `--help` option for `%%gremlin` ([Link to PR](https://github.com/aws/graph-notebook/pull/630))
- Fixed openCypher query bug regression in the [`01-About-the-Neptune-Notebook`](https://github.com/aws/graph-notebook/blob/main/src/graph_notebook/notebooks/01-Getting-Started/01-About-the-Neptune-Notebook.ipynb) sample ([Link to PR](https://github.com/aws/graph-notebook/pull/631))
Expand Down
17 changes: 17 additions & 0 deletions src/graph_notebook/decorators/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
check_if_access_regex = re.compile(r'^[a-zA-Z0-9_]+((\[\'.*?\'\])|(\[\".*?\"\])|(\[.*?\]))+$')
var_name_regex = re.compile(r'^[^\[]*')

db_to_graph_redirects = {
"statistics": "summary",
"db_reset": "graph_reset"
}

graph_to_db_redirects = {
"get_graph": "status",
"reset_graph": "db_reset",
"graph_reset": "db_reset"
}


def get_variable_injection_name_and_indices(raw_var: str, keys_are_str: bool = True):
# get the name of the dict
Expand Down Expand Up @@ -138,12 +149,15 @@ def neptune_db_only(func):
@functools.wraps(func)
def check_neptune_db(*args, **kwargs):
self = args[0]
magic_name = func.__name__
if not hasattr(self.graph_notebook_config, 'neptune_service'):
return func(*args, **kwargs)
else:
service_type = self.graph_notebook_config.neptune_service
if service_type == NEPTUNE_ANALYTICS_SERVICE_NAME:
print(f'This magic is unavailable for Neptune Analytics.')
if magic_name in db_to_graph_redirects:
print(f'\nPlease use %{db_to_graph_redirects[magic_name]} instead.')
return
else:
return func(*args, **kwargs)
Expand All @@ -155,12 +169,15 @@ def neptune_graph_only(func):
@functools.wraps(func)
def check_neptune_graph(*args, **kwargs):
self = args[0]
magic_name = func.__name__
if not hasattr(self.graph_notebook_config, 'neptune_service'):
return func(*args, **kwargs)
else:
service_type = self.graph_notebook_config.neptune_service
if service_type == NEPTUNE_DB_SERVICE_NAME:
print(f'This magic is unavailable for Neptune DB.')
if magic_name in graph_to_db_redirects:
print(f'\nPlease use %{graph_to_db_redirects[magic_name]} instead.')
return
else:
return func(*args, **kwargs)
Expand Down
Loading