question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Non-Printable Characters Lead to 'Invalid query'

See original GitHub issue

Memgraph version 2.3.1 GQLAlchemy 1.3.1

Describe the bug Non-printable characters like ‘\x13’ lead to ‘Invalid query’

To Reproduce

from gqlalchemy import Memgraph, Node, Field

db = Memgraph()

class Test(Node):
    name: str = Field()

Test(name='\x13').save(db)

Expected behavior The str is properly sanitized/escaped or the query ‘just works’.

Logs

CREATE (node:Test)   SET node.name = '\x13'  RETURN node;
---
gqlalchemy\connection.py", line 93, in execute_and_fetch
    cursor.execute(query)
mgclient.DatabaseError: Invalid query.

Additional context I have raw data that I want to load into my graph. Some of my statements fail due to the error above. The error message is not very helpful so I had to debug a bit. I think it could be in the scope of this project to do escaping/sanitizing of non-printable characters, or maybe it is a bug in memgraph itself (Python does not throw any error if I print \x13 😃 ).

At least the error message needs some improvements and more context. Maybe you could print/log the query in case of an error? I also think it would be nice to feature toggle query logging in general.

BR, Alexander

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
antaljanosbenjamincommented, Jul 29, 2022

I talked with the guys for Memgraph Lab. Actually neither Memgrgaph Lab nor mgconsole meant to handle “raw bytes”. However you can use the \u0013 form for both of them. For mgconsole the printing will be a bit strange, but it works:

memgraph> CREATE (node:Test)   SET node.name = 'this is an example\u0013some text here'  RETURN node;
+-----------------------------------------------------+
| node                                                |
+-----------------------------------------------------+
| (:Test {name: "this is an examplesome text here"}) |
+-----------------------------------------------------+
1 row in set (0.001 sec)
1 labels have been created.
1 nodes have been created.
1 properties have been updated.

For Memgraph Lab the visualization might be also a bit strange, but the test it written and read correctly, check the second screenshot. image

image

1reaction
alexanderseikcommented, Jul 29, 2022

@antaljanosbenjamin thank you for your response and further looking into this issue!

I want to add that if I run:

CREATE (node:Test)   SET node.name = 'this is an example\x13some text here'  RETURN node;

in Memgraph Lab I also get an ‘Invalid query’ response. Here I think it is because of the unescaped ‘\’, but I am not completely sure.

In general I would suggest (to memgraph/memgraph) to improve the invalid query response and provide more detail.

BR, Alexander

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selecting rows that contain Non-ASCII characters
If you're simply trying to find columns which contain non-ASCII characters, you can use the query below: SELECT * FROM table WHERE column...
Read more >
sql server - How to check for Non-Ascii Characters
Show activity on this post. What is the best way to check if a VARCHAR field has Non-Ascii Characters? CHAR(1) through CHAR(31) and...
Read more >
How to replace ASCII special characters in SQL Server
In this blog post, you will learn everything about SQL replace, especially how to replace ASCII special characters in SQL Server.
Read more >
Non-Printable Characters in SCCM - Recast Software
The Enhansoft Team was made aware of an issue with non-printable characters in several SCCM / ConfigMgr SQL Server views.
Read more >
Error "CHAR string contains invalid ASCII character" Occurs ...
Error "CHAR string contains invalid ASCII character" Occurs When Creating A Group In Non-ASCII Character User Interface (UI) Language · Issue.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found