Skip to content

fix: make API list ordering deterministic - #1642

Open
MiquelRForgeFlow wants to merge 1 commit into
PokeAPI:masterfrom
MiquelRForgeFlow:fix/deterministic-query-ordering
Open

fix: make API list ordering deterministic#1642
MiquelRForgeFlow wants to merge 1 commit into
PokeAPI:masterfrom
MiquelRForgeFlow:fix/deterministic-query-ordering

Conversation

@MiquelRForgeFlow

@MiquelRForgeFlow MiquelRForgeFlow commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Most ORM queries had no explicit ORDER BY, so the database was free to return rows in any order. The same dataset could then be serialized differently on every build, turning each api-data regeneration into a huge diff of pure reordering noise.

Give PokeApiModel a default manager that orders by primary key. Managers are inherited from abstract bases and reverse relation managers derive from the model's default manager, so this covers plain queries, reverse relations and prefetches at once, including the declarative reverse fields (Generation, GrowthRate, PokemonColor, PokemonShape, PokemonHabitat) that no serializer call site could order.

Also add tie-breakers to the partial orderings that left equal keys undefined: pokemon moves and held items, location area and pokemon encounters, past abilities and stats, berry flavors and pokedex entries.

No migration needed; call sites needing another order still override it.

AI coding assistance disclosure

Of course, the PokeApiManager was AI idea. Also used to check nothing is left out.

Contributor check list

  • I have written a description of the contribution and explained its motivation.
  • I have written tests for my code changes (if applicable).
  • I have read and understood the AI Assisted Contribution guidelines.
  • I will own this change in production, and I am prepared to fix any bugs caused by my code change.

Most ORM queries had no explicit ORDER BY, so the database was free to
return rows in any order. The same dataset could then be serialized
differently on every build, turning each api-data regeneration into a
huge diff of pure reordering noise.

Give PokeApiModel a default manager that orders by primary key. Managers
are inherited from abstract bases and reverse relation managers derive
from the model's default manager, so this covers plain queries, reverse
relations and prefetches at once, including the declarative reverse
fields (Generation, GrowthRate, PokemonColor, PokemonShape,
PokemonHabitat) that no serializer call site could order.

Also add tie-breakers to the partial orderings that left equal keys
undefined: pokemon moves and held items, location area and pokemon
encounters, past abilities and stats, berry flavors and pokedex entries.
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