fix(result_set): preserve JSON/JSONB data as objects instead of strings#38172
fix(result_set): preserve JSON/JSONB data as objects instead of strings#38172
Conversation
Code Review Agent Run #01973bActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #99e9fdActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Code Review Agent Run #8708e7Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
msyavuz
left a comment
There was a problem hiding this comment.
Would serializing-deserializing when writing/reading these columns be easier?
This fix ensures that JSON and JSONB data from databases (like PostgreSQL) is preserved as Python objects (dicts/lists) when converting result sets to pandas DataFrames. Previously, nested data types were being stringified, which broke features like Handlebars templates that need to access JSON data as objects rather than strings. The fix works by: 1. Tracking columns with nested/JSON data before stringification 2. Restoring the original Python objects when converting to pandas Fixes #25125 Co-Authored-By: Claude <noreply@anthropic.com>
pd.isna() raises ValueError when called on arrays (lists/dicts from JSON). Use a helper function that catches this exception and returns False for array values. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update test expectations to expect JSON data as preserved objects (dicts/lists) instead of stringified JSON, matching the new behavior. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When heterogeneous data (e.g., [123456, "foo"]) causes PyArrow to throw ArrowInvalid, the except branch stringifies the data before the second loop can detect nested types via pa.types.is_nested(). This means columns with nested data (lists/dicts) never get added to _nested_columns and their JSON structure is lost. Fix by checking the original data for nested types (lists/dicts) in the except branch before stringifying, preserving them in _nested_columns so they are restored as Python objects in to_pandas_df(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7eeff56 to
e867d53
Compare
Code Review Agent Run #ab00e1Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
SUMMARY
This PR fixes issue #25125 where JSON/JSONB data from databases (like PostgreSQL) was being converted to strings instead of being preserved as Python objects. This broke features like Handlebars templates that need to access JSON data as objects (e.g.,
{{this.json.key}}).Root Cause:
When processing query results, PyArrow detects JSON/JSONB columns as "nested types" and the code was stringifying them for compatibility. However, this meant the JSON objects became strings by the time they reached the frontend.
Solution:
The fix works by:
This approach:
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable - this is a backend data serialization fix.
Before:
{"source_id": "1", "json": "{'key': 'value'}"}After:
{"source_id": "1", "json": {"key": "value"}}TESTING INSTRUCTIONS
Create a PostgreSQL table with a JSONB column:
Create a Handlebars chart using this dataset
In the Handlebars template, try accessing nested JSON properties:
Verify that the JSON properties are accessible as objects, not strings
Unit Tests:
Run the new tests:
ADDITIONAL INFORMATION