Commit 8434f1a
fix(java,kotlin,python): derive the PK type from metadata instead of hardcoding it
The same bug in three ports: the generated API code hardcoded the primary-key type,
so an entity declaring `identity.primary @generation: uuid` got broken output while
its own DTO/model correctly used UUID. Not a metamodel gap — a missed reuse: every
port already had the type mapper and was already using it a few lines away.
The Kotlin generator even documented the assumption:
"for v1 we just default to \"id\" : Long for the route signatures since the
canonical Author/BaseEntity convention is a single Long PK."
It resolved the identity correctly, then threw the type away. Every entity in every
conformance corpus is a `field.long` increment PK, so no gate ever contradicted it.
- Java: `@PathVariable Long id` and `findById(Long id)` → Spring rejected a uuid path
var with 400, and the generated repository interface was un-implementable against a
UUID-keyed entity. New `SpringTypeMapper.primaryKeyJavaType()` (ADR-0039 resolving
accessors) threaded through the controller (get/update/delete/M:N/TPH polymorphic +
per-subtype) and the repository (findById/update/delete/M:N finder/TPH variants).
- Kotlin: WORSE — the generated code did not COMPILE. `@PathVariable id: Long` then
`pkField eq id` against Exposed's `Column<UUID>` is a type error, and FK columns
hardcoded `long("col").references(...)` so `Column<Long>.references(Column<UUID>)`
broke the build for ANY relationship pointing at a uuid-PK entity. PK/FK types are
now derived from the target's declared identity.
Also found: the FR-009 filter coercer had no uuid arm, so `filter[id][eq]=<uuid>`
would have ClassCastException'd at runtime; and TPH `writableFields` hardcoded the
literal "id" when excluding the PK, wrong for any PK not named `id`.
- Python: the generated FastAPI router typed every path id `int`, so a real uuid was
rejected with 422 by Pydantic and never reached the handler — the endpoint was
simply unusable, and the cross-port contract (404 for a missing row) was broken.
Now derives via the existing `type_map`, threaded through the repository Protocol,
get/update/delete, M:N traversal and TPH routes. The generated router is booted over
HTTP in a new test that proves 422 -> 404/200.
C# needed no change: it already derived the PK scalar and threaded it through every
route. It is the reference the other three were fixed against.
Gates: java-slow CI (full reactor + Java and Kotlin integration suites incl.
Testcontainers PG) green — Kotlin integration 98/98; codegen-spring 164/164;
codegen-kotlin 279/279 with no byte-drift on existing snapshots; Python 1422 pass.
A `field.long` increment PK still generates byte-identical output.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hd5NWZ1rKau63vJzrBSpLb1 parent 61e5d8e commit 8434f1a
15 files changed
Lines changed: 1240 additions & 76 deletions
File tree
- server
- java
- codegen-kotlin/src
- main/kotlin/com/metaobjects/generator/kotlin
- test/kotlin/com/metaobjects/generator/kotlin
- codegen-spring/src
- main/java/com/metaobjects/generator/spring
- test/java/com/metaobjects/generator/spring
- integration-tests-kotlin/src/test/kotlin/com/metaobjects/integration/kotlin/api/generated
- python
- src/metaobjects/codegen/generators
- tests
- codegen
- integration
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1076 | 1076 | | |
1077 | 1077 | | |
1078 | 1078 | | |
1079 | | - | |
| 1079 | + | |
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
| |||
1105 | 1105 | | |
1106 | 1106 | | |
1107 | 1107 | | |
1108 | | - | |
| 1108 | + | |
1109 | 1109 | | |
1110 | 1110 | | |
1111 | 1111 | | |
| |||
1231 | 1231 | | |
1232 | 1232 | | |
1233 | 1233 | | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
1234 | 1256 | | |
1235 | 1257 | | |
1236 | 1258 | | |
| |||
Lines changed: 13 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
141 | 148 | | |
142 | 149 | | |
143 | 150 | | |
| |||
258 | 265 | | |
259 | 266 | | |
260 | 267 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
266 | 274 | | |
267 | 275 | | |
268 | 276 | | |
| |||
0 commit comments