Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] If a node attribute value contains an apostrophe, nx_translator().to_cypher_queries(G) breaks because the string values are contained in a single quote instead of double. #318

Open
joshtracy3 opened this issue Sep 18, 2024 · 3 comments
Assignees
Labels
bug bug

Comments

@joshtracy3
Copy link

joshtracy3 commented Sep 18, 2024

Memgraph version Which version did you use?
1.6.0

Environment Some information about the environment you are using Memgraph
on: operating system, how do you connect, with or without docker, which driver
etc.

Operating System: Darwin
OS Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
OS Release: 23.6.0
OS Architecture: arm64
Full Platform Info: macOS-14.6.1-arm64-arm-64bit

Connecting with docker. Not sure about which driver

Describe the bug A clear and concise description of what the bug is.
When a string attribute value on a node contains an apostrophe, the nx_translator().to_cypher_queries(G) will break. It seems to be because string values are enclosed by a single quote instead of double quotes.

To Reproduce Steps to reproduce the behavior:

  1. Run the following python code
import networkx as nx
from gqlalchemy import Memgraph
from gqlalchemy.transformations.translators.nx_translator import NxTranslator

from warnings import filterwarnings

filterwarnings("ignore")

memgraph = Memgraph("127.0.0.1", 7687)
memgraph.drop_database()
graph = nx.Graph()
graph.add_nodes_from([(1, {"labels": "First", "name": "Josh's Laptop"}), 2, 3])
graph.add_edges_from([(1, 2, {"type": "EDGE_TYPE"}), (1, 3)])

nx_translator = NxTranslator()
for query in nx_translator.to_cypher_queries(graph):
    memgraph.execute(query)

Expected behavior A clear and concise description of what you expected to
happen.

I would expect that the queries should be seemlessly created and executed.

@katarinasupe
Copy link
Contributor

Hi @joshtracy3 thank you for reporting this. It can definitely be handled better internally, but I tried running this and it worked:

graph.add_nodes_from([(1, {"labels": "First", "name": "Josh\\'s Laptop"}), 2, 3])

Let me know if it works for you. Btw. what are you working on?

@joshtracy3
Copy link
Author

@katarinasupe yes this works if you escape the apostrophe's. There also seems to be an issue if the name contains a backslash. I just updated the functions to_cypher_labels and to_cypher_values in nx_translator to double quotes. Seems to work alright. I'm working on an entity linkage problem.

@katarinasupe
Copy link
Contributor

Feel free to open a PR @joshtracy3 😄 Thank you for letting me know what works. I hope Memgraph is performing well for your use case.

If you still haven't, join our Discord server or schedule an office hours call for more questions.

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

No branches or pull requests

3 participants