age icon indicating copy to clipboard operation
age copied to clipboard

Python driver: Unicode in cypher statements

Open theisi opened this issue 2 years ago • 1 comments

Describe the bug A unicode character (code point >128) in a cypher query raises the exception SqlExecutionError: InvalidEscapeSequence.

How are you accessing AGE (Command line, driver, etc.)? Python driver

What is the command that caused the error?

import age
ag = age.connect('test_graph', host="/var/run/postgresql", user="postgres")
ag.execCypher("CREATE (n:Test {name: %s})", params=('abcö',))

Expected behavior Write the unicode string to the database.

Environment (please complete the following information):

  • Release 1.4.0 for PG 14

Additional context AGE expects strings encoded with Unicode UTF-16 code points in the form of \uXXXX. However, cursor.mogrify() in age.py returns UTF-8 encoded byte strings. A simple decode, encode sequence can solve the problem for low code points:

cypher = (
    cursor.mogrify(cypherStmt, params)
    .decode('utf-8')
    .encode('unicode-escape')
    .decode('utf-8')
    .replace('\\x', '\\u00')
)

instead of

cypher = str(cursor.mogrify(cypherStmt, params))
cypher = cypher[2:len(cypher)-1]

theisi avatar Jan 07 '24 17:01 theisi

This issue is stale because it has been open 45 days with no activity. Remove "Abondoned" label or comment or this will be closed in 7 days.

github-actions[bot] avatar May 11 '24 00:05 github-actions[bot]

This issue is stale because it has been open 60 days with no activity. Remove "Abondoned" label or comment or this will be closed in 14 days.

github-actions[bot] avatar Jul 13 '24 00:07 github-actions[bot]

This issue was closed because it has been stalled for further 14 days with no activity.

github-actions[bot] avatar Jul 28 '24 00:07 github-actions[bot]