brucezepplin
brucezepplin

Reputation: 9752

py2neo: AttributeError: 'function' object has no attribute 'begin'

I am using py2neo version 3 and getting the following error:

> GET http://localhost:7474/db/data/
< 200 OK [795]
Traceback (most recent call last):
  File "run_snomed_upload.py", line 63, in <module>
    sp = SnomedConceptProcessor()
  File "/home/arron/Downloads/Snomed/neo4j/snomed_concept_processor.py", line 18, in __init__
    tx = self.graph.run.begin()                                      # changed .cyhper to .run
AttributeError: 'function' object has no attribute 'begin'

code:

import re
from string import Template
from py2neo import Graph
from py2neo import watch
from worker.abstract_item_processor import BaseItemProcessor



class SnomedConceptProcessor(BaseItemProcessor):
    statement = Template("CREATE (c:Concept:FSA:$label {conceptId: \"$id\", term: \"$term\", descType: $descType});")
    create_index_concept_id = "CREATE INDEX ON :Concept(conceptId)"
    create_index_term = "CREATE INDEX ON :Concept(term)"

    def __init__(self):
        watch("httpstream")
        self.graph = Graph(super().graph_url)
        tx = self.graph.run.begin() 

I have read that if using py2neo v3 then I need to change .cypher to .run which you can see I have done. Do I need to downgrade to py2neo v2 and if so how do I do that without having parallel packages?

Upvotes: 1

Views: 802

Answers (1)

Bruno Peres
Bruno Peres

Reputation: 16355

Cypher.run() is a function that receives a Cypher statement and a dictionary of parameters as parameters. You are not calling Cypher.run() as a function nor providing the parameters.

The docs says:

Note: The previous version of py2neo allowed Cypher execution through Graph.cypher.execute(). This facility is now instead accessible via Graph.run() and returns a lazily-evaluated Cursor rather than an eagerly-evaluated RecordList.

The same docs shown an usage example of Cypher.run().

>>> from py2neo import Graph
>>> graph = Graph(password="excalibur")
>>> graph.run("MATCH (a:Person) RETURN a.name, a.born LIMIT 4").data()
[{'a.born': 1964, 'a.name': 'Keanu Reeves'},
 {'a.born': 1967, 'a.name': 'Carrie-Anne Moss'},
 {'a.born': 1961, 'a.name': 'Laurence Fishburne'},
 {'a.born': 1960, 'a.name': 'Hugo Weaving'}]

Upvotes: 1

Related Questions