awslabs / amazon-neptune-tools

Tools and utilities to enable loading data and building graph applications with Amazon Neptune.
Apache License 2.0
297 stars 151 forks source link

KeyError: 'range' #216

Open echennh-zz opened 2 years ago

echennh-zz commented 2 years ago

In the __init_statics() method of GremlinUtils in neptune_python_utils/gremlin_utils.py, the code: https://github.com/awslabs/amazon-neptune-tools/blob/a1d67b1f1f7cfefa4e3c01fd4ad0566da5c3ac1d/neptune-python-utils/neptune_python_utils/gremlin_utils.py#L41 leads to a KeyError if the global doesn't already exist. I believe this should be changed to:

        globs_to_delete = ['range', 'map', 'min', 'sum', 'property', 'max']

        for glob in globs_to_delete:
            if glob in globals:
                del globals[glob]

which has patched the problem in my app's version of neptune_python_utils.

krlawrence commented 2 years ago

There was a change made in Apache TinkerPop 3.6. In that release of the Python client all the names of Gremlin steps that conflict with Python reserved words were removed and replaced with ones of the form range_. In the 3.5.x TinkerPop versions both forms existed (eg range and range_) but the range form was declared deprecated. I think the gremlin_utils.py code needs to probably be version aware and not even try to delete any globals if the gremlin-python version is 3.6.0 or higher. Thanks for pointing out this issue.

krlawrence commented 2 years ago

The version of the client can be checked using something like this:

from gremlin_python import __version__ as gremv
print(gremv.version)
iowusu commented 2 years ago

I am getting the same error. Client version 3.6.0

iowusu commented 2 years ago

it looks like this update get you pass this error

del globals['range_']
del globals['map']
del globals['min']
del globals['sum_']
del globals['property']
 del globals['max_']
hungnguyendinh1999 commented 1 year ago

I'm not sure how to bypass this error. Temporarily I'm doing this (very bad) practice which seems to work. Highly NOT recommended.

globs_to_delete = ['range', 'map', 'min', 'sum', 'property', 'max']

for glob in globs_to_delete:
    if glob not in globals():
        globals()[glob] = glob

GremlinUtils.init_statics(globals())