RedisGraph / redisgraph-py

RedisGraph python client
https://redisgraph.io
BSD 3-Clause "New" or "Revised" License
189 stars 49 forks source link

Commit on empty graph throws syntax error #30

Closed daniel-j-h closed 4 years ago

daniel-j-h commented 5 years ago

When calling .commit() (or .flush() which calls .commit()) on an empty graph we still generate a query string and send it over the wire resulting in a syntax error. We should probably simply check if the graph is empty and then don't do anything.

Reproducible with

docker run -p 6379:6379 -it --rm redislabs/redisgraph:1.0.15

and redisgraph==1.7 from pip

from redis import Redis
from redisgraph import Node, Edge, Graph

r = Redis()
g = Graph("test", r)

g.commit()

results in

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/daniel/py/cosmos/.env/lib/python3.6/site-packages/redisgraph/client.py", line 136, in commit
    return self.query(query)
  File "/home/daniel/py/cosmos/.env/lib/python3.6/site-packages/redisgraph/client.py", line 155, in query
    response = self.redis_con.execute_command("GRAPH.QUERY", self.name, q)
  File "/home/daniel/py/cosmos/.env/lib/python3.6/site-packages/redis/client.py", line 775, in execute_command
    return self.parse_response(connection, command_name, **options)
  File "/home/daniel/py/cosmos/.env/lib/python3.6/site-packages/redis/client.py", line 789, in parse_response
    response = connection.read_response()
  File "/home/daniel/py/cosmos/.env/lib/python3.6/site-packages/redis/connection.py", line 642, in read_response
    raise response
redis.exceptions.ResponseError: Syntax error at offset 8 near ' '
swilly22 commented 5 years ago

Hi @daniel-j-h, thanks for the report, I'll address this issue soon, should be an easy fix.