SeaQL/sea-orm · error

Failed to get string

Error message

Failed to get string

What it means

This panic is produced by `.expect("Failed to get string")` in ProxyRow's PostgreSQL conversion (src/driver/sqlx_postgres.rs:558). When a column's type name is VARCHAR/CHAR/TEXT/NAME, the driver decodes `Option<String>` from sqlx and panics if decoding fails. This happens when the actual value is not a decodable text type, or the row/column metadata is stale or out of range.

Source

Thrown at src/driver/sqlx_postgres.rs:558

                            Value::Double(row.try_get(c.ordinal()).expect("Failed to get double"))
                        }
                        #[cfg(feature = "postgres-array")]
                        "FLOAT8[]" | "DOUBLE PRECISION[]" => Value::Array(
                            sea_query::ArrayType::Double,
                            row.try_get::<Option<Vec<f64>>, _>(c.ordinal())
                                .expect("Failed to get double array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::Double(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "VARCHAR" | "CHAR" | "TEXT" | "NAME" => Value::String(
                            row.try_get::<Option<String>, _>(c.ordinal())
                                .expect("Failed to get string"),
                        ),
                        #[cfg(feature = "postgres-array")]
                        "VARCHAR[]" | "CHAR[]" | "TEXT[]" | "NAME[]" => Value::Array(
                            sea_query::ArrayType::String,
                            row.try_get::<Option<Vec<String>>, _>(c.ordinal())
                                .expect("Failed to get string array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::String(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        "BYTEA" => Value::Bytes(
                            row.try_get::<Option<Vec<u8>>, _>(c.ordinal())
                                .expect("Failed to get bytes"),

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Verify the real column type with information_schema.columns and correct the schema or cast (`col::text`) in the query.
  2. Rebuild the query so column metadata (PgTypeInfo) is re-fetched fresh after any ALTER TABLE.
  3. Match sea-orm and sqlx versions and rebuild; decode strictness differs between sqlx versions.
  4. Check whether the column is a custom type/domain (e.g. citext) requiring an sqlx feature or a cast to plain text.
  5. Replace expect with an error mapped to DbErr::Custom that names the column for diagnosis.

Example fix

// before
"VARCHAR" | "CHAR" | "TEXT" | "NAME" => Value::String(
    row.try_get::<Option<String>, _>(c.ordinal()).expect("Failed to get string"),
)
// after (cast in SQL to guarantee text)
// SELECT name::text AS name FROM ...
"VARCHAR" | "CHAR" | "TEXT" | "NAME" => Value::String(
    row.try_get::<Option<String>, _>(c.ordinal())
        .map_err(|e| DbErr::Custom(format!("text decode failed col {}: {e}", c.ordinal())))?,
)
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the column is a text type before reading:
// SELECT data_type FROM information_schema.columns
//   WHERE table_name=$1 AND column_name=$2;  -- expect character varying/text/char/name
// Or cast: SELECT col::text FROM ...

Type guard

fn is_text_col(c: &ProxyColumn) -> bool {
    matches!(c.ty.as_str(), "VARCHAR" | "CHAR" | "TEXT" | "NAME")
}

Try / catch

std::panic::catch_unwind(|| read_row(row))
    .map_err(|p| DbErr::Custom(format!("string decode panic: {p:?}")))?;

Prevention

When it happens

Trigger: Reading a text-typed column where the underlying data is bytea or another non-text type, querying a view/expression whose returned type no longer matches VARCHAR/TEXT, a custom domain type over text that sqlx can't decode to String, or an out-of-range ordinal due to stale column metadata.

Common situations: Schema changed after the proxy cached the column list, citext or custom text domains with missing sqlx support, passing a bytea column mislabeled as TEXT by a shim/driver, or sqlx version mismatch changing how text decoding validates types.

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/c57ab030c0edb0c1. Report an issue: GitHub.