neo4j-contrib / py2neo

EOL! Py2neo is a comprehensive Neo4j driver library and toolkit for Python.
https://py2neo.org
Apache License 2.0
22 stars 7 forks source link

Doubtful error while using NodeMatcher #888

Closed N3kox closed 3 years ago

N3kox commented 3 years ago

Hi, here i'm coding like this (assume node exists):

# -*- coding:UTF-8 -*-
import py2neo
print(py2neo.__version__) # 4.2.0

db = Graph("my db stuff")
print(db.nodes.match().where("_.name='alice'"))
# totally works well

print(db.nodes.match("People", name="alice").first())
# failed

Both match() and NodeMatcher failed when I tried to fill properties. And TraceBack like this:

File "/Users/mac/PycharmProjects/webSpider4KG/webSpider/src/test.py", line 26, in <module>
    print(db.nodes.match("People", name="alice").first())
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/py2neo/matching.py", line 94, in first
    return self.graph.evaluate(*self._query_and_parameters())
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/py2neo/database.py", line 388, in evaluate
    return self.begin(autocommit=True).evaluate(cypher, parameters, **kwparameters)
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/py2neo/database.py", line 853, in evaluate
    return self.run(cypher, parameters, **kwparameters).evaluate(0)
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/py2neo/database.py", line 805, in run
    entities=entities))
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/py2neo/internal/connectors.py", line 285, in run
    return self._run_1(statement, parameters, graph, keys, entities)
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/py2neo/internal/connectors.py", line 248, in _run_1
    cx.fetch()
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/neobolt/direct.py", line 419, in fetch
    return self._fetch()
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/neobolt/direct.py", line 461, in _fetch
    response.on_failure(summary_metadata or {})
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/neobolt/direct.py", line 751, in on_failure
    handler(metadata)
  File "/opt/anaconda2/envs/py_bd/lib/python3.7/site-packages/py2neo/internal/connectors.py", line 281, in _fail
    raise GraphError.hydrate(metadata)
py2neo.database.ClientError: SyntaxError: Invalid input '{': expected "+" or "-" (line 1, column 33 (offset: 32))
"MATCH (_:People) WHERE _.name = {1} RETURN _"

It seems like there's something wrong with properties loading, because there's no '{' or number 1 within my input. I doubt whether function "_property_conditions" in matching.py performs bad while parsing input properties.

technige commented 3 years ago

It looks like you have an incompatibility between your py2neo version and your Neo4j version. The parameter syntax changed from {param} to $param and older versions of py2neo will not be aware of this. Upgrade py2neo, and this will hopefully work.

N3kox commented 3 years ago

Upgrade from 4.2.0 to 2021.0.1 It works as expected, thanks a lot.