2

I'm running an app on Heroku using GrapheneDB, Tornado, py2neo.

I'm trying to use py2neo's Cypher transactions.

I can run this locally:

graphenedb_url = os.environ.get("GRAPHENEDB_URL", "http://localhost:7474/")
service_root = neo4j.ServiceRoot(URI(graphenedb_url).resolve("/"))
graph_db = service_root.graph_db
session = cypher.Session()

but when I deploy to Heroku, I get:

2014-10-06T20:33:34.626356+00:00 app[web.1]:   File "main.py", line 33, in <module>
2014-10-06T20:33:34.626364+00:00 app[web.1]:     session = cypher.Session()
2014-10-06T20:33:34.626367+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/cypher.py", line 127, in __init__
2014-10-06T20:33:34.626435+00:00 app[web.1]:     self._graph_db = self._service_root.graph_db
2014-10-06T20:33:34.626456+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 462, in graph_db
2014-10-06T20:33:34.626550+00:00 app[web.1]:     return GraphDatabaseService.get_instance(self.__metadata__["data"])
2014-10-06T20:33:34.626571+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 338, in __metadata__
2014-10-06T20:33:34.626641+00:00 app[web.1]:     self.refresh()
2014-10-06T20:33:34.626662+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 360, in refresh
2014-10-06T20:33:34.626732+00:00 app[web.1]:     self._metadata = ResourceMetadata(self._get().content)
2014-10-06T20:33:34.626756+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/neo4j.py", line 365, in _get
2014-10-06T20:33:34.626838+00:00 app[web.1]:     product=self._product)
2014-10-06T20:33:34.626842+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 803, in get
2014-10-06T20:33:34.627276+00:00 app[web.1]:     return rq.submit(redirect_limit=redirect_limit, **kwargs)
2014-10-06T20:33:34.627279+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 388, in submit
2014-10-06T20:33:34.627281+00:00 app[web.1]:     http, rs = submit(self.method, uri, self.body, headers)
2014-10-06T20:33:34.627282+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/py2neo/packages/httpstream/http.py", line 328, in submit
2014-10-06T20:33:34.627288+00:00 app[web.1]:     raise SocketError(code, description, host_port=uri.host_port)
2014-10-06T20:33:34.627290+00:00 app[web.1]: py2neo.packages.httpstream.http.SocketError: Connection refused
2014-10-06T20:33:34.626336+00:00 app[web.1]: Traceback (most recent call last):
2014-10-06T20:33:35.495790+00:00 heroku[web.1]: Process exited with status 1
2014-10-06T20:33:35.505975+00:00 heroku[web.1]: State changed from starting to crashed

I also tried:

session = cypher.Session(URI(graphenedb_url).resolve("/"))

But that doesn't even work locally. I've tried looking through the Graphene Docs, but no luck.

Any advice?

UPDATE: If I do:

session = cypher.Session(os.environ.get("GRAPHENEDB_URL"))
tx = session.create_transaction()
tx.append("MATCH n RETURN n") 
results = tx.execute()
for r in results[0]:
      r.values[0]

I get:

Node('http://localhost:0/db/data/node/40')
Node('http://localhost:0/db/data/node/41')
Node('http://localhost:0/db/data/node/42')

I'm guessing that port should be 7474 instead of 0? Or shouldn't that be Node('GRAPHENEDB_URI/db/data/node/40') instead of localhost?

luisdaniel
  • 907
  • 11
  • 20
  • Are you sure you're pointing to the /db/data/ endpoint? Your default should be "http://localhost:7474/db/data/" and similarly for your GrapheneDB url. – Nicole White Oct 06 '14 at 20:52
  • so I tried `cypher.Session(os.environ.get("GRAPHENEDB_URL"))` and I get another error after I try to for-loop through a transaction after execute: `SocketError: Can't assign requested address` Let me try and see via the console if it's a problem with some other part of the code. – luisdaniel Oct 06 '14 at 21:02
  • I'm Alberto from GapheneDB. Which version of Neo4j are you using? Can you please check if this also happens without transactions? – albertoperdomo Oct 06 '14 at 21:10
  • Hi Alberto, I have: `graph.neo4j_version > (2, 1, 3, u'')` I am able to execute batches: I get `200 OK` and the correct URI in the logs. – luisdaniel Oct 06 '14 at 21:18
  • Alberto, I've updated my question after further investigation. – luisdaniel Oct 06 '14 at 21:31
  • did you add the graphenedb add-on? What does `heroku config` show? (remove the password(s9 if there is any in the output) – Michael Hunger Oct 06 '14 at 22:22
  • Yes: `GRAPHENEDB_URL: http://xxxxxx:xxxxxxxx@xxxxxxx.xxxx.stations.graphenedb.com:xxxx`Like I said, adding nodes and rels via `writeBatch` works, and I even get a response code `200` and a `POST` to the correct URL, but not with `cypher.Session` – luisdaniel Oct 06 '14 at 22:46
  • Thanks @luisdaniel for the additional info. See answer below. – albertoperdomo Oct 07 '14 at 10:16

1 Answers1

4

This is a bug in Neo4j. The issue with the transaction commit URL was fixed in 2.1.5, but the URLs for nodes are still wrong.

I've updated the issue and it has been reopened.

AFAIK it only affects the transaction endpoint so other endpoints of the REST interface should be ok.

The only workaround I can think of is using URL rewriting in Py2neo, as documented here.

I hope this is fixed soon and I'm really sorry I don't have any other option for you to work around this issue.

albertoperdomo
  • 1,941
  • 12
  • 14
  • Thanks Alberto. I checked Graphene DB dashboard and I see GrapheneDB is already using 2.1.5 "Neo4j Community Edition 2.1.5" and I'm still getting the error when I try to access the nodes. I mean, I could also do: `for r in results[0]: r.values[0].__uri__._URI__set_host("graphenedbURL.com/")`, but it's kind of dirty . – luisdaniel Oct 07 '14 at 16:17
  • But have you created a new database? We have added support for 2.1.5 but unless you haven't moved to a new instance, you instance will still be on 2.1.3. Can you confirm? – albertoperdomo Oct 07 '14 at 17:15
  • I deleted the addon, then re-added it: `heroku addons:add graphenedb:chalk --version v215`, load the data succesfully (I can see it in the "Neo4j Web Admin interface", which states v2.1.5), but when I try cypher.Session, it still breaks with the same error as above. Sorry to be a pain. There must be something else I'm doing wrong. – luisdaniel Oct 07 '14 at 17:42
  • 2
    I have been able to reproduce the issue. I will investigate and update the answer as soon as we have a fix for it. Thanks for your help. – albertoperdomo Oct 07 '14 at 19:32
  • Any way I can get around this for now? Suggestions? – luisdaniel Oct 09 '14 at 15:39
  • I updated the answer but I didn't leave a new comment. For now it seems you can only rely on the rewrites, until the issue is fixed in the next release of Neo4j. You can also follow the progress at https://github.com/neo4j/neo4j/issues/2985 – albertoperdomo Oct 11 '14 at 05:58