Skip to content

fix round-trip compound ids with a null segment#2717

Closed
lsmith77 wants to merge 1 commit into
zenstackhq:devfrom
lsmith77:fix/rest-compound-id-null-segment
Closed

fix round-trip compound ids with a null segment#2717
lsmith77 wants to merge 1 commit into
zenstackhq:devfrom
lsmith77:fix/rest-compound-id-null-segment

Conversation

@lsmith77

@lsmith77 lsmith77 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #2716

RestApiHandler serializes a null segment of a compound id as an empty
string (makeCompoundId joins the segments), emitting ids like 200-01|
for a record whose optional id field is null. But coerce then runs that
empty segment through type coercion on parse (parseInt('') → NaN → 400),
so the handler rejects the very id it just emitted — any model with a
nullable field in its external/compound id has rows unaddressable by their
own id.

Fix: coerce gains an emptyAsNull flag, passed only from the id-parsing
paths (makeIdFilter, makeIdConnect). An empty segment for an optional
field now parses as null (matched via IS NULL), mirroring serialization.
Filter-value coercion is unchanged.

Known limitation: an empty trailing/middle segment is ambiguous — an optional String field with the actual value "" serializes identically to null, so on parse it always resolves to null. (Numeric/Boolean/etc. types are unaffected: "" was never a valid value there, so the only thing an empty segment can mean is null.) This PR picks "null wins" as the simplest unambiguous rule.

We could explore other options:

  • global config
  • model specific config
  • OR matching both

Obviously the entire NULL case could also be rejected because it doesn't gurantee uniqueness.

@lsmith77

Copy link
Copy Markdown
Contributor Author

I guess I will close this. NULLable columns should just not be part of a compound identifier.

@lsmith77 lsmith77 closed this Jun 17, 2026
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.

RestApiHandler emits compound ids it cannot parse back when a nullable id field is null

1 participant