fetchone() on a non-unique lookup key silently returns an arbitrary row
A repo looked up regions by a color-derived key (packed RGB -> annotation id) with a plain SELECT ... WHERE key = ? + fetchone(). There is no UNIQUE constraint on that column and no ORDER BY, so when several rows share the key the returned row is whichever the storage engine yields first, not the intended one.
Measured in the shipped data: 1327 region rows but only 86 distinct color/annotation ids; a single id was shared by 191 abbreviations (one id maps to many subregions). The label image encodes a per-pixel color, so a click resolves to an id, but that id is far from unique.
Lesson: never assume a derived or encoded identifier (color, hash prefix, slug) is unique. If a column is a lookup key, add a UNIQUE constraint (fail loudly), or use ORDER BY for determinism, or return all matches instead of fetchone(). Silent arbitrary selection is the worst outcome; it looks like it works until the data shifts.