Skip to content

fix: give a null value set in ExecuteUpdate on a JSON column its own refusal - #74

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
claude/null-set-json-update-message-2cef26
Oct 17, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
claude/null-set-json-update-message-2cef26

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #57

Problem

ExecuteUpdate that sets a value set inside a ToJson() column to null is refused by ValueSetSqlGuard, which is right. But the message gave the non-null reason: to_jsonb writing a JSON array where the document holds the literal. A null never writes an array.

Measured against PostgreSQL 17, with the refusal disabled (details in #57):

  • A constant null and a null parameter both reach the server as jsonb_set("Doc", '{MaybeTags}', to_jsonb(NULL)), because the provider inlines a null parameter. They fail with 42804 (untyped NULL).
  • A value that may be null (r.Id > 0 ? null : some) is typed. jsonb_set is strict, so it returns NULL for the whole document: 23502 on this required column, and an erased document on an optional one.

So the refusal stays. Only the message changes.

Change

  • Null (constant or parameter): a message of its own. It says what is refused and that the UPDATE would write NULL as the whole document. The workarounds it names were verified live: load the entity and call SaveChanges (which writes JSON null), or set the whole JSON property or a complex property that contains the set.
  • May be null (a conditional with a NULL branch, or a nullable column): keeps the to_jsonb message and adds the whole-document NULL.
  • Not null: the original message, unchanged.

The guard refuses exactly the setters it refused before. Only the Refusal text depends on the new checks.

Also in this PR:

  • The docs/efcore.md table row for ExecuteUpdate to null names the reason and the workarounds, and claim E27 follows it.
  • Changelog lines in the root CHANGELOG.md and the EF package's CHANGELOG.md.
  • A translation for the null write ('null'::jsonb gives {"t": null}) is a separate 9.1.0 enhancement: Translate ExecuteUpdate to null for a value set inside a JSON column #72.

Tests

  • ExecuteUpdateGuardTests (no database): constant null, null parameter, a conditional with a null branch, a nullable column, and a required column. Each asserts which reasons its message names and which it leaves out.
  • ExecuteUpdateJsonTests (live):
    • The null cases and the may-be-null case are refused with their messages, and the row still loads.
    • The two workarounds write the null and match r.Doc.MaybeTags == null on the server.
    • The existing non-null test also asserts that the null reason is absent.
  • Proven by reverting the fix: with ValueSetSqlGuard.cs restored to main, the 4 new unit tests and 2 new live refusal tests fail on their message assertions. ThrowsExactly still passes, so the refusal fires either way, and the message is what changed.
  • CI=true dotnet test on the whole solution, integration included: green.

🤖 Generated with Claude Code

@CaffeinatedCoder CaffeinatedCoder added this to the 9.1.0 milestone Oct 17, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference labels Oct 17, 2026
…refusal

Setting a value set inside a ToJson() column to null with ExecuteUpdate
is still refused, but the message gave the to_jsonb JSON-array reason,
which only applies to a value. A null constant or parameter reaches the
server as jsonb_set(doc, path, to_jsonb(NULL)): 42804, and where
PostgreSQL can type the NULL, jsonb_set returns NULL for the whole
document. It now gets its own message naming that and the workarounds
(SaveChanges, or the whole JSON property). A value that may be null keeps
the to_jsonb message and adds the whole-document NULL. What is refused
is unchanged.

Closes #57

Found-By: OT
Defect-Class: SQL

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/value-sets Value set families and wrapper arities bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Null value set in ExecuteUpdate on a JSON column is refused with the to_jsonb message

1 participant