Skip to content
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

regression: JSON columns can not be parsed into String anymore since 0.8 #3633

Open
ilka-schulz opened this issue Dec 9, 2024 · 1 comment
Labels

Comments

@ilka-schulz
Copy link

ilka-schulz commented Dec 9, 2024

Bug Description

If have a table with one column having the JSON type (internally defined as LONGTEXT by MariaDB). I used to be able to decode this with query_as into a String. Roughly since version 0.8 this panics:

error occurred while decoding column 1: mismatched types; Rust type alloc::string::String (as SQL type VARCHAR) is not compatible with SQL type BLOB

Minimal Reproduction

CREATE TABLE IF NOT EXISTS my_table (
    name VARCHAR(64) PRIMARY KEY,
    json_definition JSON
    CHECK (JSON_VALID(json_definition))
);
INSERT INTO my_table (name, json_definition) VALUES ("foo", "{\"bar\":true}");
/*
let POOL = MySqlPoolOptions::new()
                .max_connections(100)
                .acquire_timeout(Duration::from_secs(30))
                .idle_timeout(Duration::from_secs(10))
                .connect_with({
                    let options = MySqlConnectOptions::new()
                        .host(CONFIG.get().unwrap().db_host.as_str())
                        .username("api")
                        .password(CONFIG.get().unwrap().db_password.as_str())
                        .charset("utf8mb4")
                        .database("warehouse")
                        .log_statements(LevelFilter::Debug)
                        .log_slow_statements(
                            LevelFilter::Warn,
                            std::time::Duration::from_millis(1000),
                        );
                    options
                })
                .await
                .unwrap();
*/
let row: Option<(String, String)> =
    sqlx::query_as("SELECT name, json_definition FROM my_table WHERE name=?")
        .bind("foo")
        .fetch_optional(POOL)
        .await
        unwrap();

Info

  • SQLx version: 0.8.2 (it works fine on sqlx 0.7.4)
  • SQLx features enabled: [ "runtime-tokio-rustls" , "mysql", "chrono" ]
  • Database server and version: MariaDB 10.11.6
  • Operating system: Debian 11
  • rustc --version: rustc 1.85.0-nightly (4d669fb34 2024-12-08)
@ilka-schulz ilka-schulz added the bug label Dec 9, 2024
@abonander
Copy link
Collaborator

Likely caused by #3387.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants