Skip to content

fix(mysql): use lenient flag comparison for ENUM types#4154

Open
a4501150 wants to merge 1 commit intolaunchbadge:mainfrom
a4501150:fix/mysql-enum-tidb-compat-0.8
Open

fix(mysql): use lenient flag comparison for ENUM types#4154
a4501150 wants to merge 1 commit intolaunchbadge:mainfrom
a4501150:fix/mysql-enum-tidb-compat-0.8

Conversation

@a4501150
Copy link

@a4501150 a4501150 commented Feb 5, 2026

Summary

MySQL-compatible databases like TiDB may return ENUM columns with additional flags like NOT_NULL or NO_DEFAULT_VALUE. The previous exact flag comparison in MySqlTypeInfo::eq() caused type mismatches even though both sides were valid ENUM types.

This change makes ENUM comparison check only that both types have the ENUM flag set, ignoring other flags that don't affect type compatibility.

The Problem

When using #[derive(sqlx::Type)] on a Rust enum to decode from a MySQL ENUM column, decoding fails with:

mismatched types; Rust type `MyEnum` (as SQL type `ENUM`) is not compatible with SQL type `ENUM`

The issue is that MySqlTypeInfo::__enum() creates type info with only the ENUM flag (0x100), but the database may return columns with additional flags like NOT_NULL | ENUM (0x101). The strict equality check self.flags == other.flags fails.

The Fix

For ENUM types, only check that both sides have the ENUM flag set:

if self.flags.contains(ColumnFlags::ENUM) && other.flags.contains(ColumnFlags::ENUM) {
    return true;
}

Testing

  • All existing sqlx-mysql tests pass
  • Tested against TiDB Cloud with ENUM columns successfully

Fixes #3750
Refs #1241

MySQL-compatible databases like TiDB may return ENUM columns with
additional flags like NOT_NULL or NO_DEFAULT_VALUE. The previous
exact flag comparison caused type mismatches even though both sides
were valid ENUM types.

This change makes ENUM comparison check only that both types have the
ENUM flag set, ignoring other flags that don't affect type compatibility.

Fixes launchbadge#3750
Refs launchbadge#1241
@a4501150 a4501150 force-pushed the fix/mysql-enum-tidb-compat-0.8 branch from d94e9ca to c043fd6 Compare February 5, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deriving sqlx::Type on an enum fails to decode a MySql enum

1 participant