Skip to content

Bug: Python binding creation of big JSON data mutates in deeply nested values #282

@humrochagf

Description

@humrochagf

Ladybug version

v0.15.1

What operating system are you using?

Arch Linux

What happened?

Hey, I continued my tests on storing big json objects into the database and noticed that an unwanted mutation of some dict values is happening in deeply nested json.

Are there known steps to reproduce?

To reproduce it make sure you have the following libs installed for better visualization of the result:

pytest==9.0.2
pytest-icdiff==0.9
real_ladybug==0.15.1

Then put this code in a bug.py file:

import json

from real_ladybug import Connection, Database

def test_nested_json():
    db = Database("database.lbug")

    conn = Connection(db)
    conn.execute(
        """
        INSTALL json;
        LOAD json;
        CREATE NODE TABLE IF NOT EXISTS User
        (id SERIAL PRIMARY KEY, meta JSON);
        """
    )

    data = {
        "id": "http://localhost:8000/actors/testuser",
        "ap_data": {
            "id": "http://localhost:8000/actors/testuser",
            "type": "Person",
            "name": "",
            "summary": "",
            "username": "testuser",
            "inbox": "http://localhost:8000/actors/testuser/inbox",
            "outbox": "http://localhost:8000/actors/testuser/outbox",
            "public_key": {
                "id": "http://localhost:8000/actors/testuser#main-key",
                "owner": "http://localhost:8000/actors/testuser",
                "public_key_pem": (
                    "-----BEGIN PUBLIC KEY-----\n"
                    "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAni2p5Ni2mVmHKFlOFA5w\n"
                    "zBLTZS3cEdiQ/IBqeSKYcKU4TFEhaFaVy3Be4pL+vFwX+iEXpvAznEhaC6oTU2zC\n"
                    "EaXFhmVInsZ3kzrz2vTeXsOIwJ4auR8fFziwewXYXUgT0/KmSlNaYMz1PbXxPS+P\n"
                    "DHL7E6ovJSau8Hj7UMDpF6W0Xty8PoU/Kw9Fyt3SXBHz6h5hvNXTiqS2HxWDbtz/\n"
                    "j5tZlpvxiZ/sFN2w/bsotlbe2QOF5HuLA/w7B3E1Tan8jLNO4qXEHffdUZEl92ad\n"
                    "dqnhsH9MJbRp6YfNnRMd1NaHu+rDUjTur34r5oVEz766oU/ZnGlGpJsvaQmUiMW8\n"
                    "XQIDAQAB\n"
                    "-----END PUBLIC KEY-----\n"
                ),
            },
            "manually_approve_followers": False,
            "@context": [
                "https://www.w3.org/ns/activitystreams",
                "https://w3id.org/security/v1",
                {"manuallyApprovesFollowers": "as:manuallyApprovesFollowers"},
            ],
        },
        "is_local": True,
        "created_at": "2026-02-25T00:54:29.987623Z",
    }


    response = conn.execute(
        """
        CREATE (n:User {meta: to_json($meta)})
        RETURN n.id as id, cast(n.meta AS STRING) as meta;
        """,
        parameters={
            "meta": data,
        },
    )

    response_data = json.loads(response.rows_as_dict().get_all()[0]["meta"])

    assert response_data == data

Then you can run the following:

pytest -vv bug.py

You should get this output error:

Image

Metadata

Metadata

Assignees

No one assigned

    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