Repository navigation
fix(mysql): decode derived enums from NOT NULL ENUM columns - #4435
Open
Juice-de-Orange wants to merge 1 commit into
Open
Juice-de-Orange wants to merge 1 commit into
Juice-de-Orange wants to merge 1 commit into
Conversation
The `Type` derive only generates `type_info()` for MySQL, so the default `compatible()` compares the column's type info with `__enum()`, which for string types requires all column flags to be equal. A `NOT NULL` ENUM column reports `NOT_NULL | ENUM | NO_DEFAULT_VALUE`, so `try_get` failed with "Rust type `Foo` (as SQL type `ENUM`) is not compatible with SQL type `ENUM`". Emit a `compatible()` that only checks the `ENUM` flag, the same way the derive already overrides `compatible()` for SQLite, and add a regression test with `NOT NULL`, `NOT NULL DEFAULT` and indexed ENUM columns.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Does your PR solve an issue?
fixes #3750, fixes #1379
#[derive(sqlx::Type)]on an enum only generatestype_info()for MySQL, socompatible()falls back to comparing the column'sMySqlTypeInfowithMySqlTypeInfo::__enum(), and for string typesPartialEqrequires all column flags to be equal. ANOT NULLENUM column reportsNOT_NULL | ENUM | NO_DEFAULT_VALUE(NOT_NULL | ENUMwith a default, plusMULTIPLE_KEY/PRIMARY_KEYwhen indexed andBINARYwith a_bincollation) on both MySQL 8 and MariaDB 10.11, sotry_getfails with "Rust typeFoo(as SQL typeENUM) is not compatible with SQL typeENUM". The existing test only uses nullable, unindexed columns, which is the one case where the flags match.The derive now also emits a
compatible()for MySQL that checks theENUMflag through a new#[doc(hidden)] MySqlTypeInfo::__is_enum(), like it already does for SQLite (which delegates to&str).type_info()and parameter binding are unchanged, andPartialEq for MySqlTypeInfois left alone (unlike #4154, which relaxed the equality check itself and was closed by its author). Happy to delegate to<str as Type<MySql>>::compatibleinstead if you'd rather have the looser check.Regression test:
test_derive_strong_enum_not_nullintests/mysql/derives.rsdecodesNOT NULL,NOT NULL DEFAULTand indexed ENUM columns. It fails onmainwith the error above and passes with this change, on MySQL 8.0 and MariaDB 10.11.Is this a breaking change?
No. Decoding a derived enum from these columns was a runtime error before and works now; nullable ENUM columns and encoding behave exactly as before.