Repository navigation
fix: keep card updates inside the deck and stop PUT from inserting - #97
Merged
Merged
Conversation
…-scope # Conflicts: # app/schemas.py
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.
PUT /api/decks/{deck_id}/cards/sentINSERT ... ON CONFLICT (id) DO UPDATE, which had two bugs (advanced-alchemy'supsert_manyhad the same ones before #95):cards_id_seq, so the nextPOST /api/decks/{id}/cards/took the same id fromnextvaland failed on the primary key (422).Restricting the conflict update to the same deck would fix only the first one, since an unknown id never conflicts and still gets inserted. So
CardsRepository.upsert_cardsis nowupdate_cardsand sends one statement:If fewer rows come back than ids were sent, it raises
NotFoundError(404). The use case never reachescommit(), so the rows that did match are rolled back. A missing deck also gives 404.A
schemas.CardUpdatesvalidator rejects duplicate ids in one request with a 422. Before this, Postgres raisedON CONFLICT DO UPDATE command cannot affect row a second timeand the request failed with an unhandled error.This changes behavior: PUT no longer creates cards, so clients use POST for new ones.
Tests: the two bug tests failed on main and pass now. New tests cover a mixed request with one unknown id (404, nothing updated) and duplicate ids (rejected with no SQL sent). The existing one-statement test still passes.
just testpasses at 100% coverage, and ruff and ty are clean. AGENTS.md describes the new statement.