Skip to content
This repository has been archived by the owner on Mar 18, 2019. It is now read-only.

cypher query with path produces item_to_str error #3

Open
johngoodleaf opened this issue May 9, 2013 · 1 comment
Open

cypher query with path produces item_to_str error #3

johngoodleaf opened this issue May 9, 2013 · 1 comment

Comments

@johngoodleaf
Copy link

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'

@Spaider
Copy link

Spaider commented Sep 18, 2013

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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants