Skip to content

codegen: a declared id:integer is server-assigned and out of the create body (#302) - #311

Merged
Sorcecoder merged 2 commits into
mainfrom
fix/302-create-server-assigned-id
Sep 1, 2026
Merged

Sorcecoder merged 2 commits into
mainfrom
fix/302-create-server-assigned-id

Conversation

@Sorcecoder

Copy link
Copy Markdown
Contributor

Fixes #302 — the anchor of the docs↔codegen conformance sweep. docs/ai/00-designing.md:155 promises 'omit id OR declare it as integer → server-assigned BIGSERIAL, out of the create body.' The generator honored that only for an omitted id; a declared id: integer leaked into the create body as required client data (id: Set(item.id)), so a client couldn't POST and let the DB assign — and fixed-body bulk create collided on the pk.

Fix: one shared discriminator Entity::id_is_server_assigned() (true for omitted OR declared-integer; false for string/uuid), routed through six codegen sites — model/DTO id-default, both active_sets variants, OpenAPI walk_schemas+request_schema, and testgen. A server-assigned id is #[serde(default)]/NotSet/readOnly and dropped from probe bodies; string/uuid pks are byte-identical (verified by scaffolding both and diffing). Deleted tenancy_create_pk_override (the seed-dodge that was masking this green). Also corrected two stale 500-JC0510 testgen comments to 422-JC0422 (#296).

585 lib tests + integration/doc pass; 4 golden tests updated to the corrected contract, 1 new test added. No version bump.

Sorcecoder and others added 2 commits September 1, 2026 19:22
…ta (#302)

docs/ai/00-designing.md promises `omit id` and `declare id:integer` behave
identically — both a server-assigned auto-increment pk, out of the create body.
Codegen violated its own doc: a declared integer id stayed required in the
Model/{Entity}Request, the insert did `id: Set(item.id)`, OpenAPI advertised it
as client-writable, and testgen posted it — so `POST` without id got 422.

Route the server-assigned decision (synthetic OR declared integer) through one
discriminator, `Entity::id_is_server_assigned`, so every surface agrees:
- genroute: Model + {Entity}Request drop id (`#[serde(default)]`); insert leaves
  it `NotSet` (active_sets AND active_sets_pinning)
- openapi: a declared integer id is `readOnly` on the component and excluded
  from the create request schema
- testgen: the create probe omits id; the id-echo asserts a server-assigned pk
  instead of a client value; removed the now-unnecessary tenancy pk-override

A declared string/uuid id stays client-supplied (byte-identical, verified).
Also fix two stale testgen comments: a same-module FK violation is 422 JC0422
(not 500 JC0510) since #296.
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.

codegen ergonomics: create requires a client-supplied PK; PATCH is a full-PUT

1 participant