veekun/pokedex

Pokémon forms don't have unique orders

Nixill opened this issue · 1 comments

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

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:

pokedex/pokedex/db/tables.py

Lines 1874 to 1875 in 3c550f1

order = Column(Integer, nullable=False, autoincrement=False,
doc=u'The order in which forms should be sorted within all forms. Multiple forms may have equal order, in which case they should fall back on sorting by name.')

pokedex/pokedex/db/tables.py

Lines 1867 to 1873 in 3c550f1

form_order = Column(Integer, nullable=False, autoincrement=False,
doc=u"""The order in which forms should be sorted within a species' forms.
Multiple forms may have equal order, in which case they should fall
back on sorting by name. Used in generating `pokemon_forms.order`
and `pokemon.order`.
""")

I think we only ever used this for Arceus and Genesect (and previously Rotom).
Looks like this was changed in 0b81ea0#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: 811eada#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