Repository navigation
Commit 42d9fe1
committed
fix: make API list ordering deterministic
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.
Add tie-breakers to the partial orderings that left equal keys undefined,
ending every order_by() with the primary key: pokemon moves and held
items, location area and pokemon encounters, past abilities, stats and
types, form and pokemon types, berry flavors, pokedex entries and
encounter method rates. The few calls left untouched already order by
order_by("id"), which is the primary key.
Document in the manager that a distinct(*fields) call has to spell out a
matching order_by(), since PostgreSQL requires the leading ORDER BY
expressions to match the DISTINCT ON ones. A plain distinct() is fine,
because the primary key is already part of the selected row.
Add two regression tests that enforce the ordering, one for a declarative
reverse relation and one for rows tying on the whole ORDER BY. Both insert
rows with primary keys out of order, so both fail without this fix.1 parent f0deda3 commit 42d9fe1
4 files changed
Lines changed: 101 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1021 | 1021 | | |
1022 | 1022 | | |
1023 | 1023 | | |
1024 | | - | |
| 1024 | + | |
1025 | 1025 | | |
1026 | 1026 | | |
1027 | 1027 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
165 | 167 | | |
166 | 168 | | |
167 | 169 | | |
| 170 | + | |
168 | 171 | | |
169 | 172 | | |
170 | 173 | | |
| |||
230 | 233 | | |
231 | 234 | | |
232 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
233 | 251 | | |
| 252 | + | |
| 253 | + | |
234 | 254 | | |
235 | 255 | | |
236 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1053 | 1053 | | |
1054 | 1054 | | |
1055 | 1055 | | |
1056 | | - | |
| 1056 | + | |
1057 | 1057 | | |
1058 | 1058 | | |
1059 | 1059 | | |
| |||
1081 | 1081 | | |
1082 | 1082 | | |
1083 | 1083 | | |
1084 | | - | |
| 1084 | + | |
1085 | 1085 | | |
1086 | 1086 | | |
1087 | 1087 | | |
| |||
1597 | 1597 | | |
1598 | 1598 | | |
1599 | 1599 | | |
1600 | | - | |
| 1600 | + | |
1601 | 1601 | | |
1602 | 1602 | | |
1603 | 1603 | | |
| |||
1739 | 1739 | | |
1740 | 1740 | | |
1741 | 1741 | | |
1742 | | - | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
1743 | 1745 | | |
1744 | 1746 | | |
1745 | 1747 | | |
| |||
2629 | 2631 | | |
2630 | 2632 | | |
2631 | 2633 | | |
2632 | | - | |
| 2634 | + | |
2633 | 2635 | | |
2634 | 2636 | | |
2635 | 2637 | | |
| |||
2638 | 2640 | | |
2639 | 2641 | | |
2640 | 2642 | | |
2641 | | - | |
| 2643 | + | |
2642 | 2644 | | |
2643 | 2645 | | |
2644 | 2646 | | |
| |||
2946 | 2948 | | |
2947 | 2949 | | |
2948 | 2950 | | |
2949 | | - | |
| 2951 | + | |
2950 | 2952 | | |
2951 | 2953 | | |
2952 | 2954 | | |
| |||
2990 | 2992 | | |
2991 | 2993 | | |
2992 | 2994 | | |
2993 | | - | |
| 2995 | + | |
2994 | 2996 | | |
2995 | 2997 | | |
2996 | 2998 | | |
| |||
3033 | 3035 | | |
3034 | 3036 | | |
3035 | 3037 | | |
3036 | | - | |
| 3038 | + | |
3037 | 3039 | | |
3038 | 3040 | | |
3039 | 3041 | | |
| |||
3061 | 3063 | | |
3062 | 3064 | | |
3063 | 3065 | | |
3064 | | - | |
| 3066 | + | |
3065 | 3067 | | |
3066 | 3068 | | |
3067 | 3069 | | |
| |||
3086 | 3088 | | |
3087 | 3089 | | |
3088 | 3090 | | |
3089 | | - | |
| 3091 | + | |
3090 | 3092 | | |
3091 | 3093 | | |
3092 | 3094 | | |
| |||
3097 | 3099 | | |
3098 | 3100 | | |
3099 | 3101 | | |
3100 | | - | |
| 3102 | + | |
3101 | 3103 | | |
3102 | 3104 | | |
3103 | 3105 | | |
| |||
3361 | 3363 | | |
3362 | 3364 | | |
3363 | 3365 | | |
3364 | | - | |
| 3366 | + | |
3365 | 3367 | | |
3366 | 3368 | | |
3367 | 3369 | | |
| |||
3535 | 3537 | | |
3536 | 3538 | | |
3537 | 3539 | | |
3538 | | - | |
| 3540 | + | |
| 3541 | + | |
| 3542 | + | |
3539 | 3543 | | |
3540 | 3544 | | |
3541 | 3545 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1309 | 1309 | | |
1310 | 1310 | | |
1311 | 1311 | | |
| 1312 | + | |
1312 | 1313 | | |
1313 | 1314 | | |
1314 | 1315 | | |
| |||
1321 | 1322 | | |
1322 | 1323 | | |
1323 | 1324 | | |
| 1325 | + | |
1324 | 1326 | | |
1325 | 1327 | | |
1326 | 1328 | | |
| |||
1573 | 1575 | | |
1574 | 1576 | | |
1575 | 1577 | | |
1576 | | - | |
1577 | | - | |
| 1578 | + | |
| 1579 | + | |
1578 | 1580 | | |
1579 | 1581 | | |
| 1582 | + | |
1580 | 1583 | | |
1581 | 1584 | | |
1582 | 1585 | | |
| |||
2686 | 2689 | | |
2687 | 2690 | | |
2688 | 2691 | | |
| 2692 | + | |
| 2693 | + | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
| 2703 | + | |
| 2704 | + | |
| 2705 | + | |
| 2706 | + | |
| 2707 | + | |
| 2708 | + | |
| 2709 | + | |
| 2710 | + | |
| 2711 | + | |
| 2712 | + | |
| 2713 | + | |
| 2714 | + | |
2689 | 2715 | | |
2690 | 2716 | | |
2691 | 2717 | | |
| |||
4591 | 4617 | | |
4592 | 4618 | | |
4593 | 4619 | | |
| 4620 | + | |
| 4621 | + | |
| 4622 | + | |
| 4623 | + | |
| 4624 | + | |
| 4625 | + | |
| 4626 | + | |
| 4627 | + | |
| 4628 | + | |
| 4629 | + | |
| 4630 | + | |
| 4631 | + | |
| 4632 | + | |
| 4633 | + | |
| 4634 | + | |
| 4635 | + | |
| 4636 | + | |
| 4637 | + | |
| 4638 | + | |
| 4639 | + | |
| 4640 | + | |
| 4641 | + | |
| 4642 | + | |
| 4643 | + | |
| 4644 | + | |
| 4645 | + | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
4594 | 4652 | | |
4595 | 4653 | | |
4596 | 4654 | | |
| |||
0 commit comments