neo4j / neo4j-python-driver

Neo4j Bolt driver for Python
https://neo4j.com/docs/api/python-driver/current/
Other
899 stars 186 forks source link

Crash when using spatial type as parameters #496

Closed stellasia closed 3 years ago

stellasia commented 3 years ago

Hi folks!

I can't seem to get the spatial type working, just getting a crash (stack trace attached).

import neo4j
print(neo4j.__version__)

from neo4j.spatial import WGS84Point
from neo4j import GraphDatabase, basic_auth
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", ""), encrypted=False)
point = WGS84Point(dict(x=2, y=48))
cypher = "WITH $point as point RETURN [point.x, point.y]"
params = {"point": point}
with driver.session() as session:
    session.run(cypher, params)

Full stack trace is attached. neo_spatial.log

Also, only error in server logs is:

2021-02-11 18:00:06.353+0000 ERROR Client triggered an unexpected error [Neo.DatabaseError.General.UnknownError]: Unknown statement ID: -1. Existing IDs: [], reference 1c40d17c-1c03-4b40-b422-ceeef7fc49ec.
robsdedude commented 3 years ago

The constructor of WGS84Point takes a tuple or list of floats. Your example works if you replace

point = WGS84Point(dict(x=2, y=48))

with

point = WGS84Point((2.0, 48.0))

a type check on the driver side would make for a more helpful error message.

You can find more details in the driver's API docs.

stellasia commented 3 years ago

Arf, my bad, thanks for this!

Also, apparently, the elements in the tuple need to be floats, it fails with the same error if I use int (ok no one wants to use int for latitude and longitude... except me when testing :) ).

technige commented 3 years ago

@stellasia Not really your bad. The usage isn't obvious. We should probably coerce these into floats internally.