Repository navigation
Fix: Encode strings as JSON in JSONQueryString where clauses (fixes #1118) - #1438
Open
shadialhasan wants to merge 1 commit into
Open
shadialhasan wants to merge 1 commit into
shadialhasan wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Fixes #1118.
In
piccolo/query/operators/json.py,JSONQueryString.clean_value()previously exempted allstrinstances from JSON encoding (if not isinstance(value, (str, QueryString)): value = dump_json(value)). As identified in #1118, when filtering JSON/JSONB columns using operators such asGetChildElement(arrow) orGetElementFromPath(from_path), plain string values (e.g.'hello world') were passed as unquoted strings instead of valid JSON strings (e.g.'"hello world"'), leading to type mismatch issues in database JSON comparisons.This PR updates
JSONQueryString.clean_value()to:QueryStringinstances unchanged.load_json(). If the string is already valid JSON (e.g.'{"message": "hello world"}','["a", "b"]', or'"already quoted"'), it is preserved as-is.load_json()fails on a plain string (e.g.'hello world','foo'), it encodes it withdump_json().dump_json().Tests Added
TestJSONQueryString(tests/query/operators/test_json.py) validating:'hello world'->'"hello world"').QueryStringexpressions are preserved.==,eq) and inequality (!=,ne) operator compilation to SQL with parameterized query arguments.Eng. MHD. Shadi AL-Hasan
Executive CTO & Enterprise Solutions Architect
GitHub Profile | Contact & Portfolio