You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "omaurel-socha (via GitHub)" <gi...@apache.org> on 2023/09/12 12:23:08 UTC
[GitHub] [age] omaurel-socha opened a new issue, #1229: Python Driver's _nodeToJson() returns invalid JSON
omaurel-socha opened a new issue, #1229:
URL: https://github.com/apache/age/issues/1229
**Describe the bug**
I am trying some cypher queries using the python driver.
When iterating the results of a query, The function .toJson() returns a JSON string containing a trailing comma in the "properties" field.
As a result, the JSON is invalid and it is not possible to convert it into a dict using json.loads() for example.
**How are you accessing AGE (Command line, driver, etc.)?**
- Python Driver
**What data setup do we need to do?**
```
def testJson(self):
print("\n------------------------------")
print("Test 6: Testing JSON output.....")
print("--------------------------------\n")
ag = self.ag
with ag.connection.cursor() as cursor:
try:
ag.cypher(cursor, "CREATE (n:Person {name: %s}) ", params=('Joe',))
ag.cypher(cursor, "CREATE (n:Person {name: %s}) ", params=('Jack',))
ag.cypher(cursor, "CREATE (n:Person {name: %s}) ", params=('Andy',))
ag.cypher(cursor, "CREATE (n:Person {name: %s}) ", params=('Smith',))
ag.cypher(cursor, "CREATE (n:Person {name: %s}) ", params=('Tom',))
# You must commit explicitly
ag.commit()
except Exception as ex:
print(ex)
ag.rollback()
print(" -------- TESTING JSON #1 --------")
cursor = ag.execCypher("MATCH (n) RETURN n")
for row in cursor:
# json.loads will fail if the json str is not properly formatted
as_dict = json.loads(row[0].toJson())
print("Vertex.toJson() returns a correct json string.")
```
**What is the command that caused the error?**
```
for row in cursor:
as_dict = json.loads(row[0].toJson())
```
**Expected behavior**
The correct behavior would return valid JSON when calling .toJson().
**Additional context**
The problem originates in _nodeToJson(). The way the buffer writing iteration is done in the properties field will always add a trailing comma.
[I have submitted a PR to fix the issue](https://github.com/apache/age/pull/1228)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@age.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Python Driver's _nodeToJson() returns invalid JSON [age]
Posted by "jrgemignani (via GitHub)" <gi...@apache.org>.
jrgemignani commented on issue #1229:
URL: https://github.com/apache/age/issues/1229#issuecomment-2174488343
@rafsun42 Could you look into this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Python Driver's _nodeToJson() returns invalid JSON [age]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #1229:
URL: https://github.com/apache/age/issues/1229#issuecomment-2171948577
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [age] markgomer commented on issue #1229: Python Driver's _nodeToJson() returns invalid JSON
Posted by "markgomer (via GitHub)" <gi...@apache.org>.
markgomer commented on issue #1229:
URL: https://github.com/apache/age/issues/1229#issuecomment-1727873921
I tested this myself and I can confirm the vertexes created are looking like this:
`{label:Person, id:844424930131969, properties:{name: Joe, }}::VERTEX`
Which is not a correct JSON string.
Also, I confirm that the PR #1228 fixes the issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [age] jimenasansav commented on issue #1229: Python Driver's _nodeToJson() returns invalid JSON
Posted by "jimenasansav (via GitHub)" <gi...@apache.org>.
jimenasansav commented on issue #1229:
URL: https://github.com/apache/age/issues/1229#issuecomment-1730097205
Hi @omaurel-socha! Thank you very much for bringing up this issue. And thank you @markgomer for confirming it.
Our team is now going through the PR to get it merged.
@dehowef
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@age.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org