Skip to content

fix(django-google-spanner): support JSONField read and write operations - #19007

Merged
sakthivelmanii merged 1 commit into
mainfrom
fix_json_field_spanner
Nov 13, 2026
Merged

sakthivelmanii merged 1 commit into
mainfrom
fix_json_field_spanner

Conversation

@sakthivelmanii

@sakthivelmanii sakthivelmanii commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Reading and writing Django JSONField values previously failed on Cloud Spanner because JSON values were not adapted to Spanner's native JSON parameter type on writes, and parsed JSON objects returned by the Spanner driver were passed back into Django's string-based JSON deserializer on reads.

This change enables full JSONField support in the Cloud Spanner Django backend, including against the Cloud Spanner Emulator:

  • Reading and writing JSON objects, arrays, and primitive values (strings, numbers, and booleans), as well as custom JSON encoders and decoders.
  • Preserving the distinction between SQL NULL (when assigning None to a nullable field) and JSON null (when using Value(None, JSONField())).
  • Filtering and querying on nested JSON keys and paths, including key transforms and key existence lookups (has_key, has_keys, and has_any_keys).
  • Avoiding redundant JSON serialization and parsing between Django and the Cloud Spanner client library on both the read and write paths.

@sakthivelmanii
sakthivelmanii requested a review from a team as a code owner November 6, 2026 11:37

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Django's JSONField in the Google Cloud Spanner backend by adding utility functions to adapt and convert JSON values, along with corresponding unit and mock server tests. Feedback is provided to optimize the recursive _unwrap_json_object serialization helper by checking for standard Python types first, which avoids expensive isinstance checks on standard elements in performance-critical paths.

@olavloite olavloite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but we should update the PR description, as it does not fit the actual implementation anymore.

@sakthivelmanii
sakthivelmanii merged commit e92588b into main Nov 13, 2026
85 checks passed
@sakthivelmanii
sakthivelmanii deleted the fix_json_field_spanner branch November 13, 2026 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants