espeed / bulbs

A Python persistence framework for graph databases like Neo4j, OrientDB and Titan.
http://bulbflow.org
Other
622 stars 83 forks source link

[Neo4J] Empty response from DB leads to TypeError #113

Closed Joacchim closed 10 years ago

Joacchim commented 10 years ago

Hello,

I'm not even sure it is either a bug or the wanted behavior, but I ended up getting a TypeError Exception from a gremlin query.

The query was ended by a ".fill(table)" operation, which in my understanding (after a bit of treasure hunting) leads to an empty response (with response.content != Null, with the dictionnary being "{u'data': [], u'columns': []}" )

I tried to check within the base code (initialize_elements function) as well as within the Neo4J client code (get_results method) how it is managed, but it seems that even when the reponse only contains one result which is not an iterable, it should work.

My guess is thus that the Result is built atop an empty content, and cannot be managed by the base code.

Here is the end of the stack trace given to me by python (I removed my own code):

  File ".../test.py", line 68, in function
    result = g.gremlin.query(request)
  File "/usr/local/lib/python2.7/dist-packages/bulbs/gremlin.py", line 63, in query
    return initialize_elements(self.client, resp)
  File "/usr/local/lib/python2.7/dist-packages/bulbs/utils.py", line 62, in initialize_elements
    return (initialize_element(client, result) for result in response.results)
TypeError: 'Neo4jResult' object is not iterable

This isn't a blocker at all, but I thought it was worth mentionning, in case it's an unintended behavior.

Thanks for thre Great Work !

espeed commented 10 years ago

The Bulbs Gremlin API has three methods: query(), command(), and execute(). See...

Use the query() method when you are returning vertices or edges -- as you have found, it returns an iterator that will initialize elements to appropriate Vertex, Edge, or Model class.

Use the command() method when you issue a Gremlin command and expect a single return value in the response.

Use the execute() method when you are returning anything else, such as a Gremlin script that returns a list of names, or in this case table data -- execute() returns a generic Response object:

>>> resp = g.gremlin.execute(script, params)
>>> resp.content  # json content from server

See https://github.com/espeed/bulbs/blob/master/bulbs/neo4jserver/client.py#L219

espeed commented 10 years ago

Resolved AFAIK.

Joacchim commented 10 years ago

Thanks for the answer. I originally used the query() because I expected something to be returned, and got this exception when doing an unexpected request. I understand that the API has multiple entry points for different purposes, but I was surprised to get an exception.

If this is the expected behavior then yes, this was a non-issue. Thanks for your time !