neo4j-contrib / py2neo

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

Schema Object contains GraphService instead of Graph #855

Closed cdboer closed 3 years ago

cdboer commented 4 years ago

Version Information

Expected Behaviour

The following excerpt should just work. (if i am not mistaken)

from py2neo import GraphService

gs = GraphService(address=address, user=user, password=password)
db = gs["neo4j"]
db.schema.create_uniqueness_constraint("Entity", "id")

Actual Behaviour

>>> db.schema.create_uniqueness_constraint("Entity", "id")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\users\claas\anaconda3\lib\site-packages\py2neo-5.0b1-py3.8.egg\py2neo\database.py", line 658, in create_uniqueness_constraint
    self.graph.run(cypher).close()
AttributeError: 'GraphService' object has no attribute 'run'

The docs state this on the Schema object:

The schema resource attached to a Graph instance.

The object contained in Graph.schema.graph is a GraphService object and not a Graph object, hence the previous error.

>>> db.schema.graph
<GraphService uri='bolt://neo4j@localhost:7687' secure=False user_agent=None>
>>> type(db.schema.graph)
<class 'py2neo.database.GraphService'>

I think that this is unintended.

Workaround

A workaround is to replace the GraphService object in Schema.graph by the graph database object of the database that you want to create or delete constraints for/from.

from py2neo import GraphService

gs = GraphService(address=address, user=user, password=password)
db = gs["neo4j"]
db.schema.graph = db
db.schema.create_uniqueness_constraint("Entity", "id")

Steps to reproduce

The code blocks should suffice.


Thank you for py2neo. It has saved me countless hours of development!

technige commented 3 years ago

@cdboer Yup, this totally looks like a bug. I must have wired in the wrong object on Schema creation.

technige commented 3 years ago

Fixed for 2020.1