GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python Driver's _nodeToJson() returns invalid JSON · Issue #1229 · apache/age

Python Driver's _nodeToJson() returns invalid JSON #1229

New issue
Copy link
New issue
Copy link
Closed
Closed
Python Driver's _nodeToJson() returns invalid JSON#1229
Copy link
Assignees
dehowef
Labels
bugSomething isn't working

Description

@omaurel-socha
omaurel-socha
opened on Sep 12, 2023
Issue body actions

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

Activity

  1. omaurel-socha
    added
    bugSomething isn't working
    on Sep 12, 2023
  2. markgomer commented on Sep 20, 2023

    @markgomer
    markgomer
    on Sep 20, 2023
    Contributor
    More actions

    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.

  3. jimenasansav commented on Sep 21, 2023

    @jimenasansav
    jimenasansav
    on Sep 21, 2023
    More actions

    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

  4. jrgemignani
    assigned
    dehowef
    on Apr 17, 2024
  5. github-actions commented on Jun 17, 2024

    @github-actions
    github-actionsBot
    on Jun 17, 2024 – with GitHub Actions
    More actions

    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.

  6. github-actions
    added
    StaleStale issues/PRs
    on Jun 17, 2024
  7. jrgemignani
    removed
    StaleStale issues/PRs
    on Jun 17, 2024
  8. jrgemignani commented on Jun 17, 2024

    @jrgemignani
    jrgemignani
    on Jun 17, 2024
    Contributor
    More actions

    @rafsun42 Could you look into this?

    Reacted by Rafsun Masud
  9. rafsun42 commented on Jun 21, 2024

    @rafsun42
    rafsun42
    on Jun 21, 2024
    Member
    More actions

    @jrgemignani It seems the issue was resolved by PR #1228.

  10. rafsun42
    closed this as completedon Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dehowef
    dehowef

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.