fix(generators): deleting an entity deletes its association-class links - #598
Merged
Conversation
Deleting a Booking that had ReservedRoom links crashed the generated
backend with SQLAlchemy's "Dependency rule tried to blank-out primary key
column" AssertionError: the link's FK is part of its composite primary
key, so the ORM could neither null it nor knew to delete the row. And the
generated table could not delete a link row at all, because it guessed the
row id from the first column (the price) and called /reservedroom/88.0/.
- sql_alchemy: the entity -> links relationship of every association class
carries cascade="all, delete-orphan" (both ends), so deleting an entity
deletes its link rows; the link -> entity side stays cascade-free.
- backend routers: DELETE returns a snapshot of the deleted row's columns
instead of the live ORM object, whose cascade-loaded back-references
made the JSON encoder recurse endlessly.
- react: the table binding names its row key fields (declared is_id
attribute, or both foreign keys in the backend's route order for an
association class) and getRowId builds the path from them, so
DELETE/PUT of a Room hits /room/{number}/ and of a link
/reservedroom/{booking_id}/{rooms_id}/.
Tests: end-to-end cascade from both ends and link deletion (backend),
row_key_fields serialization (react), cascade emission (sqlalchemy).
Verified live on the hotel-booking model.
ArmenSl
added a commit
that referenced
this pull request
Sep 9, 2026
…tiplicity enforcement in generated apps - Bump setup.cfg 7.14.1 -> 7.14.2 and add the v7.14.2 release notes. - Backend: modular per-file FastAPI generator (#597), association-class cascade delete and real row keys (#598), lower-bound multiplicity guards, omitted-list PUT, inherited-attribute PUT, and the generated dialog fixes (detailed prefill, request loop, delete-error banner). - Frontend submodule unchanged: develop and main are already in sync.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Deleting an entity that has association-class links (e.g. a
BookingwithReservedRoomrows) crashed the generated backend, and the generated table could not delete a link row at all.cascade="all, delete-orphan"(both ends). Their FK is part of the link's composite PK, so without the cascade SQLAlchemy raised "Dependency rule tried to blank-out primary key column" on delete.DELETEreturns a column snapshot of the deleted row instead of the live ORM object — the cascade loads back-references that made the JSON encoder recurse endlessly.row_key_fields(declaredis_idattribute, or both FKs in the backend's route order for an association class) andgetRowIdbuilds the path from them. Previously it guessed the first column of the row, which for aReservedRoomwas the price →DELETE /reservedroom/88.0/.Tests
End-to-end cascade from both ends + link deletion (backend, ASGI-driven),
row_key_fieldsserialization (react), cascade emission (sqlalchemy). Verified live against the hotel-booking model: create booking with two rooms → delete a link → delete the booking → no orphan rows.