GQLAlchemy is a library developed with the purpose of assisting in writing and running queries on Memgraph. GQLAlchemy supports high-level connection to Memgraph as well as modular query builder.
Environment
I am running Memgraph in Docker on a MacBook Pro Apple M1 Max chipset.
Bug description, reproduction and expected behaviour
The method translator.to_cypher_queries[1] is not escaping apostrophes.
Node in NetworkX graph: (15981, { 'labels': 'Word', 'Token': "Ain't", 'IPA': 'ʔ aɪ n t' })
Generated query using the aforementioned method: CREATE (:Word {Token: 'Ain't', IPA: 'ʔ aɪ n t', id: 15981});[2]
When trying to execute the query [2] in Memgraph, I get the following: Query failed: Invalid query. Which is expected because the apostrophe wasn't escaped.
The method [1] should instead return the query as follows: CREATE (:Word {Token: 'Ain\'t', IPA: 'ʔ aɪ n t', id: 15981});
Potential solution
Simple solution for the time being: escape_apostrophes = lambda x: re.compile(r"(['])").sub(r"\\'", x)
Thank you @jackabouaad for reporting this here too :) We will include it in the next release. If you're up for the open source contribution, our PRs are always open :D
Memgraph version Memgraph 2.8.0 Gqlalchemy 1.4.1
Environment I am running Memgraph in Docker on a MacBook Pro Apple M1 Max chipset.
Bug description, reproduction and expected behaviour The method
translator.to_cypher_queries
[1] is not escaping apostrophes. Node in NetworkX graph:(15981, { 'labels': 'Word', 'Token': "Ain't", 'IPA': 'ʔ aɪ n t' })
Generated query using the aforementioned method:CREATE (:Word {Token: 'Ain't', IPA: 'ʔ aɪ n t', id: 15981});
[2] When trying to execute the query [2] in Memgraph, I get the following:Query failed: Invalid query.
Which is expected because the apostrophe wasn't escaped. The method [1] should instead return the query as follows:CREATE (:Word {Token: 'Ain\'t', IPA: 'ʔ aɪ n t', id: 15981});
Potential solution Simple solution for the time being:
escape_apostrophes = lambda x: re.compile(r"(['])").sub(r"\\'", x)