I see a strange behavior with the neo4j-bolt-driver
. When I use Pycharm
to run my code it works perfectly well and for a single query to neo4j
I get the below response:
type: neo4j.node # I pulled out the type of the element.
<Node id=3820 labels={'city'} properties={'ID': 'xddy', 'name': 'california'}>
Now when I package my code and create an .egg
out of it, and then use the terminal to run the script for the same input to the same database I get the below response:
type: neo4j.node # I pulled out the type of the element.
(_3820:city {ID: 'xddy', name: 'california'})
Now have a look at the difference in the responses, the type is the same just the keys
to the object are missing.
And this leads to an
AttributeError
. Worse is I have to manually parse the data into a dict so that I can process it.
Side Effects:
try:
props = node[admin].properties
node_chain[list(node[admin].labels)[0]] = props
address.append(props['name'])
except AttributeError:
# try to convert (_3820:city {ID: 'xddy', name: 'california'})
# to {'ID': 'xddy', 'name': 'california'}
# and add it to an existing dict with the key `city`
string_rep = str(node[admin])
splitted = string_rep.split('{')
label = splitted[0].split(':')[-1].strip()
payload_string = "{ " + splitted[1][:-1]
clean = payload_string.replace("'", " ").replace(":", "':'").replace(",", "','")\
.replace("{", "{'").replace("}", "'}")
temp_dict = ast.literal_eval(clean)
payload_dict = {k.strip(): v.strip() for k, v in temp_dict.items()}
address.append(payload_dict['name'])
node_chain[label] = payload_dict
I am looking for two answers:
- Is there an issue in the bolt driver or is it just my code when run from an
egg
- Is there a better way to parse the invalid content into a dict?