Skip to content

Use a JSONPATH for quoted JSON property names on SQLite - #39378

Merged
AndriySvyryd merged 1 commit into
dotnet:mainfrom
AsadIqbal-Dev:fix/sqlite-json-quoted-name
Oct 22, 2026
Merged

AndriySvyryd merged 1 commit into
dotnet:mainfrom
AsadIqbal-Dev:fix/sqlite-json-quoted-name

Conversation

@AsadIqbal-Dev

@AsadIqbal-Dev AsadIqbal-Dev commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

Fixes #39328

When a JSON property name needs quoting and is the last segment, VisitJsonScalar wrote it as a plain ->> label (->> '"display_name"'). SQLite reads a right operand that doesn't start with $ as a literal key, so the quotes become part of the name and the lookup returns NULL. With this change, such names are written as a JSONPATH instead (->> '$."display_name"'). Names that don't need quoting still use the short label form.

Tests:

  • New Custom_naming_predicate_on_scalar_in_collection_element in JsonQuerySqliteTest. It filters on ユニコーンFraction一角獣 inside CustomOwnedCollectionBranch and returned 0 rows before the change.
  • Custom_naming_projection_everything and Custom_naming_projection_owned_reference baselines updated. They were asserting the broken form.

Ran all SQLite tests with Json, Complex or PrimitiveCollections in the class name: 4943 passed, 125 skipped, 0 failed.

I posted the plan on the issue just now. I'm happy to change the approach if you'd rather handle it elsewhere, for example in DelimitJsonPathElement.

- A property name that needs quoting was emitted as a plain ->> label, so SQLite looked up the key with the quotes included and never matched
- Added a predicate test on a quoted property inside a JSON collection element and updated the affected baselines

Fixes dotnet#39328

Copilot AI 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.

🟢 Approval recommended

No unresolved review issues were identified, and the supplied assessments indicate the changes are ready for approval.

No open issues 🎉

What changed in this PR

This pull request fixes SQLite JSON scalar lookups for quoted property names by emitting a $.-prefixed JSONPath for terminal segments that require quoting.

Changes:

  • Corrects SQLite JSON SQL generation for quoted terminal property names.
  • Adds regression coverage for quoted properties in JSON collection predicates.
  • Updates affected SQLite SQL baselines.
File Description
test/​EFCore.Sqlite.FunctionalTests/​Query/​JsonQuerySqliteTest.cs Adds regression coverage and updates expected SQL baselines.
src/​EFCore.Sqlite.Core/​Query/​Internal/​SqliteQuerySqlGenerator.cs Generates valid JSONPath operands for quoted terminal property names.

Review effort: Lite

@AsadIqbal-Dev

Copy link
Copy Markdown
Contributor Author

The two failing checks look unrelated to this SQLite-only change:

  • Cosmos (windows-2025): one test out of 7401 failed with a 409 Conflict from the emulator.
  • coverage: the npm audit step fails on the new ip-address advisory (GHSA-rxp7-6hxx-x8q5).

@AndriySvyryd AndriySvyryd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution!

@AndriySvyryd
AndriySvyryd merged commit ae93fba into dotnet:main Oct 22, 2026
20 of 22 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQLite: JSON property names that need quoting translate to a ->> path that never matches

3 participants