Skip to content

fix: return cards and decks ordered by id - #89

Merged
lesnik512 merged 1 commit into
mainfrom
fix/stable-list-order
Oct 16, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
fix/stable-list-order

Conversation

@lesnik512

Copy link
Copy Markdown
Member

The list queries had no ORDER BY, so Postgres returned rows in heap order. An UPDATE writes the new row version after the existing ones, so after a PUT the list endpoints returned the updated rows last. advanced-alchemy's upsert_many re-reads updated rows with an unordered get_many, which meant the PUT response could also come back reversed. test_create_cards and test_update_cards compare whole lists in a fixed order and failed intermittently on a reused database.

Changes:

  • CardsRepository.list_for_deck orders by Card.id.
  • CardsRepository.upsert_cards sorts the upserted rows by id in Python, since upsert_many has no order_by.
  • New DecksRepository.list_decks orders by Deck.id. ListDecksUseCase calls it in place of the bare get_many().

Tests:

  • test_cards_ordered_by_id_after_update PUTs two cards in reverse id order and checks that the PUT response and the list both come back ordered by id.
  • test_list_decks_ordered_by_id_after_update updates the first of two decks and checks the order of the deck list.

Both new tests fail on main on every run, on a fresh database too, because the updated row versions land after the untouched ones.

@lesnik512
lesnik512 merged commit 9f808e6 into main Oct 16, 2026
2 checks passed
@lesnik512
lesnik512 deleted the fix/stable-list-order branch October 16, 2026 19:53
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.

1 participant