-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uuid
type does not work correctly with MariaDB
#3039
Comments
Similar situation here, I managed to get around the issue by using |
Hi, I'm encountering a related issue and I'm not sure how to work around it. Using MariaDB 11.5.2. #[derive(Debug, Deserialize, Serialize, sqlx::FromRow)]
#[allow(non_snake_case)]
pub struct UserObjectBase {
#[sqlx(try_from = "Hyphenated")]
pub UUID: uuid::Uuid,
// ...
} I'm using MariaDB's native As you can see, I've tried doing
Removing the |
As former committer on a large Apache project, I get the desire for consistency. But I think it's actively user-hostile to return an error in a situation where it's very obvious that you've been handed a string representation of UUID, when you could instead just parse it. |
I think the issue with this isn't that it isn't obvious that there's a string, but that it isn't obvious how it's stored. If @abonander or another maintainer could comment on this and if the type mismatch I was encountering is intentional or not (and if intentional, how to fix it), that would be great. |
By the time sqlx is in |
@LawsOfScience please open a new issue. That's a different bug. It's likely because @koeninger my experience from maintaining this crate for almost 5 years now tells me that making It's much easier to teach, and for the user to remember, that If I could go back in time, maybe we'd support only the text format, or use an adapter type for binary format. Changing To be safe, I'd want to drop the trait impls entirely for a full release cycle and force the user to use an adapter type, then maybe reintroduce the impls in a future release using the text format. But frankly, only supporting text-encoded UUIDs is an incredibly shortsighted decision on the part of the MySQL developers. Taking 36 bytes to store or transmit one ID is just insane. Handling UUIDs in binary is the better choice from a purely technical perspective. MariaDB's It's for reasons like this why I will never use MySQL over Postgres. It's full of tons of really esoteric and shortsighted design decisions. By comparison, |
I don't really understand your point about more confusion on binding; I'd probably need to see an example. I made that patch after a runtime error on Making people put It doesn't ultimately matter to me, since we'll keep using a patched version of sqlx to paper over other issues we've run into anyway. Consider it as feedback - there are plenty of other people who will just run into this kind of thing and silently stop using sqlx. I understand the mysql hate, but Postgres has its share of dumb stuff as well. For instance, lack of unsigned integer types, which is the reason we backed into using MariaDB. |
Bug Description
SQLx seems to fail to decode to
Uuid
on MariaDB. I think this may be because a binary value is expected, but the select type for a UUID column on MariaDB is a hyphenated string.sqlx/sqlx-mysql/src/types/uuid.rs
Line 37 in 84d5760
Could the column type or length be checked to determine whether to decode a string or byte slice?
Minimal Reproduction
Output:
Also tested with mysql which can't create the table but does have a
uuid()
function. This gets similar failures.Info
sqlx = { version = "0.7.3", features = ["mysql", "runtime-tokio", "uuid"] }
tokio = { version = "1.36.0", features = ["full"] }
uuid = "1.7.0"
rustc --version
: rustc 1.77.0-nightly (11f32b73e 2024-01-31)The text was updated successfully, but these errors were encountered: