Commit 7fab436
fix(codegen): generated partial PATCH no longer clobbers omitted columns (C#, Kotlin)
The only generated update handler is a partial PATCH (both PATCH and PUT map to it),
but two ports overwrote every column a PATCH OMITTED — silent data loss on every
partial update, in shipped generated code:
- C# — the handler bound the body into a full `<Entity> input`; a field absent from
the JSON deserialized to its CLR default (0 / null / false / DateTime.MinValue),
and `CurrentValues.SetValues(input)` then wrote those defaults over the live
row. `PATCH {"status":"ACTIVE"}` on a wide entity destroyed every other column.
- Kotlin (base controller) — `it[field] = dto.field` for EVERY field, so an omitted
optional field's null was written over the stored value.
TS (Zod `InsertSchema.partial()`), Java and Python (present-field merges in the
generated repositories / doubles) were already correct — so this is two ports, not one.
Each broken port already had the CORRECT logic in its own TPH branch (C#'s per-subtype
JSON-body enumeration; Kotlin's `if (dto.f != null)` guard); the base handlers just
didn't use it.
Fix:
- C# base + TPH handlers deserialize each PRESENT property from the raw JSON body
(skipping the PK, and — for the base — null values), using the app's CONFIGURED
JsonSerializerOptions. The last point matters: a field.timestamp binds to
DateTimeOffset via a custom converter registered on ConfigureHttpJsonOptions, and
the first cut used default options, which can't read the wire format and 500'd (the
TPH handler had the identical latent bug — also fixed).
- Kotlin base controller null-guards OPTIONAL fields only. Required props are non-null
(Jackson 400s a body missing them before the handler runs), so they stay
unconditional — guarding them would be an always-true warning and break -Werror.
Contract: an omitted field always survives, in every port. Whether an EXPLICIT null
clears a nullable column (the absent-vs-null tristate) is deferred to FR-035.
Gate — the forcing function no existing scenario could provide: every prior update
scenario sent every non-PK column, so there was never an omitted field to clobber.
`fixtures/api-contract-conformance/scenarios/update-partial-omitted-field-survives.yaml`
PATCHes one field, OMITS the optional `bio`, and asserts (via the response AND a fresh
GET) that `bio` keeps its seed value. It runs on all five ports, both lanes (reference +
generated). Verified to FAIL on the pre-fix Kotlin generator with exactly
"expected row.bio=First computer programmer, got null" — and ONLY that scenario — then
pass after. All five ports: C# 22/22 (both lanes), Kotlin 22/22, Java 22/22, Python
44, TS both lanes.
Goldens updated (verified correct, not blind-regenerated): the C# routes unit test
pinned the old `(long id, Subscriber input, ...)` signature; the Kotlin snapshot changed
exactly one line (`it[label] = dto.label` → null-guarded, `label` being optional).
Design context for the broader work (typed patch surface, Kotlin repository generator,
optimistic concurrency) in docs/superpowers/specs/2026-07-13-generated-mutation-surface-design.md.
Its @rowVersion / ADR-0043 proposal is NOT adopted here: @autoset:onUpdate already models
"stamps on every write" and OMDB already derives its optimistic-lock column from it, so a
new attribute would violate ADR-0023 (can't-invent-what's-derivable) — a decision left to
the owner. Corrects GitHub #198; #197's premise was already refuted on that issue.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hd5NWZ1rKau63vJzrBSpLb1 parent 4771f41 commit 7fab436
6 files changed
Lines changed: 859 additions & 14 deletions
File tree
- docs/superpowers/specs
- fixtures/api-contract-conformance/scenarios
- server
- csharp
- MetaObjects.Codegen.Tests
- MetaObjects.Codegen/Generators
- java/codegen-kotlin/src
- main/kotlin/com/metaobjects/generator/kotlin
- test/resources/snapshots/entity-with-tph/acme/auth
Lines changed: 753 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| |||
Lines changed: 41 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
190 | 200 | | |
191 | | - | |
| 201 | + | |
192 | 202 | | |
193 | 203 | | |
194 | 204 | | |
195 | | - | |
196 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
197 | 223 | | |
198 | 224 | | |
199 | 225 | | |
| |||
444 | 470 | | |
445 | 471 | | |
446 | 472 | | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
447 | 478 | | |
448 | 479 | | |
449 | 480 | | |
| |||
455 | 486 | | |
456 | 487 | | |
457 | 488 | | |
458 | | - | |
| 489 | + | |
459 | 490 | | |
460 | 491 | | |
461 | 492 | | |
| |||
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
359 | 359 | | |
360 | 360 | | |
361 | 361 | | |
362 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
363 | 374 | | |
364 | 375 | | |
365 | 376 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
282 | 282 | | |
283 | 283 | | |
284 | 284 | | |
285 | | - | |
| 285 | + | |
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| |||
0 commit comments