Skip to content

Fix JSON Path Filtering Producing Incorrect Results#17

Closed
kac-axelor wants to merge 5 commits intoaxelor:devfrom
kac-axelor:json-filtering-fix
Closed

Fix JSON Path Filtering Producing Incorrect Results#17
kac-axelor wants to merge 5 commits intoaxelor:devfrom
kac-axelor:json-filtering-fix

Conversation

@kac-axelor
Copy link
Copy Markdown
Contributor

Symmetric casting for JSON path parameters

PostgreSQL's jsonpath engine requires both sides of a comparison to be the same type. Previously only the field placeholder (@) was cast to .double() or .datetime() — the parameter variable (e.g. $p0) was left uncast, causing strict type-mismatch errors at runtime. Both sides are now cast symmetrically.

Global regex for @ replacement

The @ placeholder replacement used a non-global regex, so only the first occurrence was cast. This broke between and in operators which generate multiple @ references in a single condition. Replaced with /g flag to cast all occurrences.

Safer type inference in findJsonType

findJsonType ran regex tests directly on the value without checking its type first. Passing null, undefined, or a non-string (e.g. a Date object or boolean) would either throw or produce the wrong inferred type. Added null/undefined guards and wrapped the regex checks inside a typeof value === "string" guard.

Test cases to demonstrate the issue

Added test cases that would fail without these fixes

kac-axelor and others added 5 commits March 13, 2026 18:33
- Add null and undefined guards to findJsonType
- Ensure regex tests only run on string values to avoid false positives
and errors
- Fixes 'between' and 'in' operators where only the first occurrence was
being cast
- Ensures all field placeholders in complex JSON path conditions are
correctly processed
- Casts both the field (@) and the parameter variable () to .double() or
.datetime()
- Ensures PostgreSQL jsonpath engine compares identical types, avoiding
strict type-mismatch errors
- Update query parser tests to reflect symmetric casts
@ame-axelor ame-axelor closed this Mar 17, 2026
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