veekun / pokedex

more than you ever wanted to know about Pokémon
MIT License
1.44k stars 637 forks source link

Pokémon forms don't have unique orders #282

Closed StevenH237 closed 4 years ago

StevenH237 commented 4 years ago

In the pokemon_forms table, the order column is one that looks like it should have unique values for all records, likely as a sorting order.

However, this isn't the case for this table. The forms with IDs 10057 (unknown-type Arceus) and 10196-10201 (cap-wearing Pikachus) all fail to enter a table when the table forces order to have unique values. They have values that conflict with:

Failed id/identifier Order Successful id/identifier
10057/arceus-unknown 621 10047/arceus-flying
10196/pikachu-original-cap 37 10187/pikachu-cosplay
10197/pikachu-hoenn-cap 38 10182/pikachu-rock-star
10198/pikachu-sinnoh-cap 39 10183/pikachu-belle
10199/pikachu-unova-cap 40 10184/pikachu-pop-star
10200/pikachu-kalos-cap 41 10185/pikachu-phd
10201/pikachu-alola-cap 42 10186/pikachu-libre
magical commented 4 years ago

Interesting.

The duplicate entries you listed do seem wrong, but that's not the whole story. The pokemon_forms table is allowed to contain duplicate order values, in which case you are supposed to fall back on sorting by name (which depends on language, so it can't be hardcoded).

This is documented in tables.py: https://github.com/veekun/pokedex/blob/3c550f142581776e2e12786845cfc8034428b146/pokedex/db/tables.py#L1874-L1875 https://github.com/veekun/pokedex/blob/3c550f142581776e2e12786845cfc8034428b146/pokedex/db/tables.py#L1867-L1873

I think we only ever used this for Arceus and Genesect (and previously Rotom). Looks like this was changed in https://github.com/veekun/pokedex/commit/0b81ea0c795f172c3406c0133ad84929d51186f9#diff-bf7b3287819f9022a9c8d713d9448478. Not sure whether it was intentional. That explains the duplicate entry for arceus-unknown -- that commit updated the form_order for all the regular Arceus forms but missed the special ???-type form.

The Pikachus are my fault: https://github.com/veekun/pokedex/commit/811eada23bf8dde6000b3eb05e071d1fb7ec28c2#diff-bf7b3287819f9022a9c8d713d9448478. I forgot about the cosplay forms when i set the form_order for the cap forms.

The fix would be to update the form_order column for the affected forms and rerun set_pokemon_order_columns.sql