Commit 7811a9f
fix(python-codegen): PATCH cannot mutate a write-once @autoset column (review gate)
Code-review of the ADR-0045 @autoset stamping (Kotlin clean) found a real integrity
hole in the generated Python router: the update handler passed the caller dto straight
to repo.update without stripping onCreate @autoset keys, so a caller could overwrite the
write-once createdAt via PATCH — a divergence from the Kotlin controller (which excludes
@autoset from its patch-settable set) and from the port's own ObjectManager.update
(which already does `data.pop(...)`), and one the green api-contract gate doesn't detect
(its PATCH body is name-only).
Fixes (the caller-facing @autoset surface, mirroring Kotlin):
- update handler strips every onCreate @autoset key (`dto.pop(name, None)`) before the
repo call — a caller cannot mutate createdAt via the deployed API;
- @autoset fields are excluded from _REQUIRED_FIELDS, so a caller-sent present-null on a
@required @autoset field is ignored/stamped, not a spurious 400 (Kotlin never null-checks
them either).
Regression-pinned in test_router_autoset (asserts the strip; render_router callers 26/26).
Also two byte-identical simplifier cleanups: Kotlin KotlinTypeMapper.nowExpr uses the bare
imported MetaField<*>; the Python awkward conditional-in-spread dissolves by moving the
handler comment into _auto_set_stamp_lines (call sites become a plain `*create_autoset`).
Deferred (Low, degenerate models): PK / write-through-derived exclusion in _auto_set_split
(an @autoset temporal PK or @autoset on a derived field — effectively impossible).
Refs #203, #229 (ADR-0045).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XeGSV3StPCcJGZNNJ4ZfAb1 parent c5905b8 commit 7811a9f
3 files changed
Lines changed: 38 additions & 12 deletions
File tree
- server
- java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin
- python
- src/metaobjects/codegen/generators
- tests/codegen
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
666 | | - | |
| 666 | + | |
667 | 667 | | |
668 | 668 | | |
669 | 669 | | |
| |||
Lines changed: 33 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| |||
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
111 | 122 | | |
112 | 123 | | |
113 | 124 | | |
| |||
143 | 154 | | |
144 | 155 | | |
145 | 156 | | |
146 | | - | |
| 157 | + | |
147 | 158 | | |
148 | | - | |
| 159 | + | |
| 160 | + | |
149 | 161 | | |
150 | 162 | | |
151 | | - | |
| 163 | + | |
152 | 164 | | |
153 | 165 | | |
154 | 166 | | |
| |||
378 | 390 | | |
379 | 391 | | |
380 | 392 | | |
381 | | - | |
382 | | - | |
| 393 | + | |
383 | 394 | | |
384 | 395 | | |
385 | 396 | | |
| |||
406 | 417 | | |
407 | 418 | | |
408 | 419 | | |
409 | | - | |
410 | | - | |
| 420 | + | |
411 | 421 | | |
412 | 422 | | |
413 | 423 | | |
| |||
755 | 765 | | |
756 | 766 | | |
757 | 767 | | |
758 | | - | |
759 | | - | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
760 | 783 | | |
761 | 784 | | |
762 | 785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| |||
0 commit comments