Skip to content

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

Closed

Description

@CaffeinatedCoder

ExecuteUpdate that sets a value set inside a JSON column to null is refused by ValueSetSqlGuard with InvalidOperationException, which is right. But the message describes the other case the guard refuses: to_jsonb writing a JSON array where the document holds the literal. For a null value that's misleading. It should say what is refused and what to write instead.

The failure is loud and the fix only changes a message. Found during the probing round (#52), where it came up while checking E27.

Activity

  1. added this to the 9.1.0 milestone on Oct 17, 2026
  2. added
    bug
    found-by/oracle
    area/value-sets
    package/efcore
    on Oct 17, 2026
  3. added
    severity/low
    on Oct 17, 2026
  4. CaffeinatedCoder commented on Oct 17, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Measured against PostgreSQL 17 (Testcontainers), with the guard's throw disabled to see what would be sent. "Doc" is a required ToJson() complex property, so the column is NOT NULL.

    Setter SQL sent PostgreSQL Row afterwards
    constant (StringSet?)null jsonb_set(j."Doc", '{MaybeTags}', to_jsonb(NULL)) 42804 could not determine polymorphic type unchanged
    null parameter same SQL. The provider inlines a null parameter as NULL before the guard runs 42804 unchanged
    may be null: r => r.Id > 0 ? null : some jsonb_set(…, to_jsonb(CASE WHEN … THEN NULL ELSE @some END)) 23502 null value in column "Doc" unchanged
    non-null parameter (for comparison) jsonb_set(…, to_jsonb(@p)) succeeds ["p"], row no longer loads

    In plain SQL, jsonb_set(doc, path, NULL) and jsonb_set(doc, path, to_jsonb(NULL::text[])) both return NULL. jsonb_set is strict, so a typed NULL replaces the whole document. On a required column that fails with 23502. On an optional one it would erase the document. So the refusal is right in every case. Only the message was wrong.

    Workarounds, both verified live: load the entity, set the property to null and call SaveChanges (it writes "MaybeTags": null, and the row loads null). Or SetProperty(r => r.Doc, doc) with a document that holds the null. Both rows then match r.Doc.MaybeTags == null on the server.

    The fix:

    • A definitely-null value (constant or parameter) gets its own message: what is refused, the whole-document NULL, and the two workarounds.
    • A value that may be null (a conditional with a NULL branch, or a nullable column) keeps the to_jsonb message and adds the whole-document NULL.
    • A non-null value keeps the original message.

    The set of refused setters is unchanged. A null write could be translated correctly ('null'::jsonb gives {"t": null}): #72.

  5. added a commit that references this issue on Oct 17, 2026
    9832d96
  6. CaffeinatedCoder commented on Oct 17, 2026

    @CaffeinatedCoder
    OwnerAuthor

    Oracle check (main at 3ecfa10): no oracle on main catches this (pending, expected miss). I reverse-applied #74's src/ diff on 3ecfa10 and ran every class in oracles.json, including UnionCanonicalityTests. All of them stayed green. The fix's own tests did fail (ExecuteUpdateJsonTests 2, ExecuteUpdateGuardTests 4), which shows the revert put the defect back.
    Why no oracle can catch it: the refusal itself was right, and only its wording was wrong. Error wording has no independent reference, so it is outside what the machinery checks (docs/oracles.md#what-it-does-not-see). Claim E27 is held only by those two regression tests. Neither route B step varies it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/value-setsbugfound-by/oraclepackage/efcoreseverity/low

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions