Skip to content

fix(infra): do not re-encode store defaultValues in query builders - #899

Merged
patroza merged 1 commit into
mainfrom
fix/double-encode-default-values
Sep 16, 2026
Merged

patroza merged 1 commit into
mainfrom
fix/double-encode-default-values

Conversation

@patroza

@patroza patroza commented Sep 16, 2026

Copy link
Copy Markdown
Member

Why

validateSample / store.filter({ select: [id] }) was failing inside Repository.filter as an Encoding issue on a Date — even though the select branch never decodes a document. The store already JSON-lowers defaultValues at construction (json.toJson(config?.defaultValues ?? {})). Cosmos and SQL query builders then lowered them again (defaultValues = toJson(defaultValues)). Encoding an already-ISO string through a Date codec throws Expected a valid Date.

Empirical proof: makeJsonLower({ schema: Item }).toJson({ at: new Date(...) }) yields { at: "2024-06-01T00:00:00.000Z" }; feeding that object back through the same encoder throws Expected a valid Date.

What

Stop re-encoding defaultValues in buildWhereCosmosQuery3 and buildWhereSQLQuery. Filter values still go through jsonifyFilter because they arrive as native Encoded. Memory already encodes once at construction and never again — this matches that peer.

How

  • Drop the second toJson(defaultValues) in Cosmos and SQL query builders.
  • Pin the encoder non-idempotence and the query-builder contract with tests.

Design angles: assumed goal is that store-lowered Date defaults must survive filter (including select-only / validateSample) — peers Memory (encode once at construction) vs Cosmos/SQL query builders (re-encode); follow Memory, migrate Cosmos+SQL query builders in this PR.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Stores already JSON-lower defaultValues at construction. Re-encoding an
ISO Date string through the Date codec throws "Expected a valid Date",
which failed filter({ select: [id] }) even when the select path never
decoded a document.
@patroza
patroza marked this pull request as ready for review September 16, 2026 07:34
@patroza
patroza merged commit ebffba8 into main Sep 16, 2026
4 checks passed
@patroza
patroza deleted the fix/double-encode-default-values branch September 16, 2026 07:34
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.

1 participant