Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

bug: json data insert int db is failing #592

@vi3k6i5

Description

@vi3k6i5

json data insert int db is failing

Environment details

  • OS type and version: Mac os latest
  • Python version: python --version 3.8
  • google-cloud-spanner 3.10

Steps to reproduce

  1. Insert json data in db using cursor.execute method
  2. Pass the json as dictionary without formatting it as string.

Code example

    # Create table
    cur = conn.cursor()
    cur.execute(
        """
        CREATE TABLE JsonDetails (
            DataId     INT64 NOT NULL,
            Details    JSON,
        ) PRIMARY KEY (DataId)
    """
    )
    conn.close()

    # Insert data to table
    conn = Connection(shared_instance, dbapi_database)
    conn.autocommit = True
    cur = conn.cursor()
    cur.execute(
        sql="INSERT INTO JsonDetails (DataId, Details) VALUES (%s, %s)",
        args=(123, {"name": "Jakob", "age": "26"}),
    )

Stack trace

except InvalidArgument as e:
>           raise ProgrammingError(e.details if hasattr(e, "details") else e)
E           django.db.utils.ProgrammingError: 400 Value of type STRING cannot be assigned to value, which has type JSON [at 1:33]\nUPDATE tests_detail SET value = @a0 WHERE tests_detail.id = @a1\n

Thanks!

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/python-spanner API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions