From 11e2e285c420543e3a41cb5829ce0a02b6c59909 Mon Sep 17 00:00:00 2001 From: Cameron Braid Date: Wed, 9 Aug 2023 10:41:37 +1000 Subject: [PATCH] fix: Make rust_decimal and bigdecimal decoding more lenient fixes https://github.com/readysettech/readyset/issues/143 When using readyset as a caching proxy - readyset returns a decimal with the following type info `MySqlTypeInfo { type: Decimal, flags: ColumnFlags(0x0), char_set: 33, max_size: Some(1024) }` Currently rust_decimal and bigdecimal expect an exact match for the type info `MySqlTypeInfo { type: NewDecimal, flags: ColumnFlags(BINARY), char_set: 63, max_size: None }` Therefore the following error occurs when readyset sends a valid decimal type ``` error occurred while decoding column "price": mismatched types; Rust type `core::option::Option` (as SQL type `DECIMAL`) is not compatible with SQL type `DECIMAL` ``` This patch makes the `Type for Decimal` more lenient by matching `MySqlTypeInfo` that has ColumType::Decimal | ColumnType::NewDecimal to be parsed by both rust_decimal and bigdecimal types --- sqlx-mysql/src/types/bigdecimal.rs | 4 ++++ sqlx-mysql/src/types/rust_decimal.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/sqlx-mysql/src/types/bigdecimal.rs b/sqlx-mysql/src/types/bigdecimal.rs index d763bb7f47..d072db27c5 100644 --- a/sqlx-mysql/src/types/bigdecimal.rs +++ b/sqlx-mysql/src/types/bigdecimal.rs @@ -12,6 +12,10 @@ impl Type for BigDecimal { fn type_info() -> MySqlTypeInfo { MySqlTypeInfo::binary(ColumnType::NewDecimal) } + + fn compatible(ty: &MySqlTypeInfo) -> bool { + matches!(ty.r#type, ColumnType::Decimal | ColumnType::NewDecimal) + } } impl Encode<'_, MySql> for BigDecimal { diff --git a/sqlx-mysql/src/types/rust_decimal.rs b/sqlx-mysql/src/types/rust_decimal.rs index fa387596f4..49ab2ded56 100644 --- a/sqlx-mysql/src/types/rust_decimal.rs +++ b/sqlx-mysql/src/types/rust_decimal.rs @@ -12,6 +12,10 @@ impl Type for Decimal { fn type_info() -> MySqlTypeInfo { MySqlTypeInfo::binary(ColumnType::NewDecimal) } + + fn compatible(ty: &MySqlTypeInfo) -> bool { + matches!(ty.r#type, ColumnType::Decimal | ColumnType::NewDecimal) + } } impl Encode<'_, MySql> for Decimal {