There is a problem with how SQLAlchemy stores Python Enum types when native enums are disabled and said Enum contains aliases.
class Country(enum.Enum):
GB = 'gb'
FR = 'fr'
UK = 'gb' # alias the GB item
foo = Table(
'foo',
metadata,
Column('country', Enum(Country,native_enum=False,create_constraint=False))
)>>> Country.GB
<Country.GB: 'gb'>
>>> Country.UK
<Country.GB: 'gb'>
>>> Country.GB.name
'GB'
>>> Country.UK.name
'GB'
>>>If you store the value Country.GB in the table foo it will be stored as UK instead of GB.
I believe this is caused by flipping the dictionary keys/values in Enum._setup_for_values, instead of using the name param of the enum.