sublime-cypher icon indicating copy to clipboard operation
sublime-cypher copied to clipboard

cypher query with path produces item_to_str error

Open johngoodleaf opened this issue 11 years ago • 1 comments

A cypher query of the form: start a=node(*) match p=(a) - [:ACTED_IN] -> (movie) <- [:DIRECTED] - (director) return p;

Produces this result in the ST console: Traceback (most recent call last): File "./sublime_plugin.py", line 362, in run_ File "./Cypher.py", line 130, in run File "./Cypher.py", line 118, in cypher File "./Cypher.py", line 31, in print_table File "./Cypher.py", line 31, in File "./Cypher.py", line 11, in item_to_str KeyError: 'data'

johngoodleaf avatar May 09 '13 19:05 johngoodleaf

I am not familiar with python at all, so I did not create pull request. Problem is in unicode strings processing. Here's the fix that works for me. Code converts unicode to ascii, replacing missing chars with question mark:

def item_to_str(item):
    if isinstance(item, dict):
        data = json.dumps(item['data'])
        id_ = item['self'].rsplit('/', 1)[1]

        if 'type' in item:
            return "[%s:%s %s]" % (
                id_, item['type'], data)
        else:
            return "(%s %s)" % (id_, data)
    elif isinstance(item, unicode):
        return item.encode('ascii', 'replace')
    else:
        return str(item)

Spaider avatar Sep 18 '13 07:09 Spaider