SeaQL/sea-orm · error

Failed to get string

Error message

Failed to get string

What it means

`ProxyRow` decodes MySQL string columns (CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT) with `row.try_get::<Option<String>>` and `.expect("Failed to get string")`. Since the target is `Option<String>`, NULL is tolerated — this panic means sqlx could not decode the cell as UTF-8 text at all (invalid encoding, binary data in a text column, or metadata/actual-type mismatch).

Source

Thrown at src/driver/sqlx_mysql.rs:446

                        ),
                        "FLOAT" => {
                            Value::Float(row.try_get(c.ordinal()).expect("Failed to get float"))
                        }
                        "DOUBLE" => {
                            Value::Double(row.try_get(c.ordinal()).expect("Failed to get double"))
                        }

                        "BIT" | "BINARY" | "VARBINARY" | "TINYBLOB" | "BLOB" | "MEDIUMBLOB"
                        | "LONGBLOB" => Value::Bytes(
                            row.try_get::<Option<Vec<u8>>, _>(c.ordinal())
                                .expect("Failed to get bytes")
                                .map(Box::new),
                        ),

                        "CHAR" | "VARCHAR" | "TINYTEXT" | "TEXT" | "MEDIUMTEXT" | "LONGTEXT" => {
                            Value::String(
                                row.try_get::<Option<String>, _>(c.ordinal())
                                    .expect("Failed to get string")
                                    .map(Box::new),
                            )
                        }

                        #[cfg(feature = "with-chrono")]
                        "TIMESTAMP" => Value::ChronoDateTimeUtc(
                            row.try_get::<Option<chrono::DateTime<chrono::Utc>>, _>(c.ordinal())
                                .expect("Failed to get timestamp")
                                .map(Box::new),
                        ),
                        #[cfg(all(feature = "with-time", not(feature = "with-chrono")))]
                        "TIMESTAMP" => Value::TimeDateTime(
                            row.try_get::<Option<time::PrimitiveDateTime>, _>(c.ordinal())
                                .expect("Failed to get timestamp")
                                .map(Box::new),
                        ),

                        #[cfg(feature = "with-chrono")]

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Ensure the connection and column charsets are UTF-8 capable (utf8mb4) and data is valid UTF-8
  2. Fix proxy/mock handlers to return `String` values for text columns
  3. If the column truly holds bytes, migrate it to a BLOB type so the bytes arm decodes it
  4. Regenerate entities from the current schema to eliminate metadata drift

Example fix

// before
ALTER TABLE t MODIFY col VARBINARY(255); -- read through string arm: panics
// after
ALTER TABLE t MODIFY col VARCHAR(255) CHARACTER SET utf8mb4;
Defensive patterns

Strategy: validation

Validate before calling

// Verify text columns hold valid UTF-8
SELECT COLUMN_NAME, CHARACTER_SET_NAME FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?;
// CHARACTER_SET_NAME should be utf8/utf8mb4, not binary/latin1

Type guard

fn is_valid_utf8_text(bytes: &[u8]) -> bool { std::str::from_utf8(bytes).is_ok() }

Prevention

When it happens

Trigger: A text column containing non-UTF-8 bytes (e.g. binary blobs stored in TEXT/VARCHAR, or latin1/binary charset data the driver refuses to decode as String), or mock proxy rows supplying non-string values, decoded via the proxy driver.

Common situations: Tables with mixed charset (utf8mb4 vs binary) after a migration; BLOB data accidentally read through a string-typed arm due to stale metadata; proxy/mock handlers returning byte or numeric values for VARCHAR columns.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10). Data as JSON: /api/errors/1985d815fd4677f8. Report an issue: GitHub.