Skip to content

fix(postgresql): typed filters keep braces in string literals (#70) - #71

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/70-typed-filter-braces
Oct 20, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/70-typed-filter-braces

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #70

Problem

HasComplexIndex(x => x.Code, x => x.Code != "{draft}") scaffolded WHERE "Code" <> '{{draft}}'. PostgreSQL compares against {{draft}}, a different value, so rows whose code is {draft} are indexed, and constrained when the index is unique, although the filter excludes them. The same for HasFilter<T>, AddComplexIndexFilter<T> and typed exclusion-constraint filters. Silent since 5.2.0.

The translator's literal writer escapes braces for expression templates, which are unescaped when resolved. Filters go through ResolveFilter, which has no {{ escape on purpose ('{{1,2},{3,4}}' is an array literal), so the escape was never undone.

Change

NpgsqlLinqIndexTranslator.TranslatePredicate undoes the brace escape inside single-quoted literals of the predicate it produced. ResolveFilter never reads a brace inside a literal as a placeholder, so a single brace is safe there. Typed expression indexes keep the escape they need.

Changelogs: a ### Changed answers row for #70 in the 5.5.0 entry.

Merge note: #69 adds the same ### Changed answers / ### Changed headings to the 5.5.0 changelog entries. Whichever merges second needs a trivial rebase of CHANGELOG.md and the PostgreSQL package changelog (both rows under one heading); I'll do it when the first one lands.

Tests

  • NpgsqlTypedFilterTests.Brace_in_literal_is_kept: an index filter with {draft} and {{1,2}} literals and an exclusion filter with }{ render as written.
  • verify-the-guard: with the translator change reverted, the test fails ('{{draft}}').
  • Full suite green locally, integration included.

🤖 Generated with Claude Code

Literals escape { and } as {{ and }} for expression templates, which
unescape them when resolved. A typed filter goes through the filter
resolver instead, which has no {{ escape because '{{1,2},{3,4}}' is a
valid array literal, so the braces stayed doubled: x.Code != "{draft}"
scaffolded "Code" <> '{{draft}}', a different value, and rows whose
code is {draft} were indexed although the filter excludes them.

TranslatePredicate now undoes the escape inside string literals. The
filter resolver never reads a brace inside a literal as a placeholder,
so the single brace is safe there.

Verified by reverting the translator: the new test, covering an index
filter and an exclusion-constraint filter, fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 5.5.0 milestone Oct 19, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred severity/medium Inconsistency or failure in a narrow scenario package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/indexes Complex-property, composite, unique and filtered indexes area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints labels Oct 19, 2026
The brace unescape now wraps the null-aware VisitPredicate; both test groups and both changelog entries are kept.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@CaffeinatedCoder
CaffeinatedCoder merged commit f0bdbc1 into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/70-typed-filter-braces branch October 20, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/indexes Complex-property, composite, unique and filtered indexes bug Something isn't working package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL severity/medium Inconsistency or failure in a narrow scenario silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed filters double braces in string literals: x.Code != "{draft}" renders '{{draft}}'

1 participant