SeaQL/sea-orm · error

Failed to get uuid

Error message

Failed to get uuid

What it means

ProxyRow panics with this message when sqlx's `row.try_get::<Option<uuid::Uuid>, _>` fails while converting a Postgres UUID column into Value::Uuid. try_get errors when the column is not actually a uuid type (e.g. varchar/text storing UUID strings, or bytea) or the raw value is not 16 bytes. The expect() turns this into a panic instead of a Result error.

Solutions

  1. Check the column type; if it's text/varchar, either change it to uuid (`ALTER TABLE t ALTER COLUMN id TYPE uuid USING id::uuid`) or change the entity field to String.
  2. Regenerate entities with sea-orm-cli after schema changes.
  3. Cast in the query so the driver receives uuid: `SELECT id::uuid FROM ...`.
  4. If the value is genuinely not a valid UUID (e.g. '0000'), fix the data — sqlx cannot decode invalid UUID bytes.
  5. Enable the with-uuid feature on sea-orm/sea-query/sqlx consistently.

Example fix

// before: id stored as text -> panic "Failed to get uuid"
// after: migrate column to real uuid type
-- ALTER TABLE users ALTER COLUMN id TYPE uuid USING id::uuid;
Defensive patterns

Strategy: validation

Validate before calling

let t = sqlx::query(
    "SELECT data_type FROM information_schema.columns WHERE table_name=$1 AND column_name=$2"
).bind("users").bind("id")
 .fetch_one(db).await?;
assert_eq!(t.get::<String,_>("data_type"), "uuid");

Type guard

fn as_uuid(v: &str) -> Option<uuid::Uuid> {
    uuid::Uuid::parse_str(v).ok()
}

Try / catch

let row = std::panic::catch_unwind(|| {
    // conversion reading the uuid column
});
match row {
    Ok(r) => Ok(r),
    Err(_) => Err(DbErr::Custom("uuid column decode failed".into())),
}

Prevention

When it happens

Trigger: Selecting a column declared TEXT/VARCHAR (or bytea) that the entity treats as UUID; casting results incorrectly; a custom id generator storing non-uuid data in a uuid column; using `RETURNING` with expressions that change the type.

Common situations: Legacy schemas storing UUIDs as text; migrations where id columns were recreated with the wrong type; ORMs/libs mismatched where column type changed from uuid to text; raw SQL expressions like `id::text` returned but expected uuid.

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

Appendix: source

Thrown at src/driver/sqlx_postgres.rs:928

                            feature = "postgres-array"
                        ))]
                        "TIMETZ[]" => Value::Array(
                            sea_query::ArrayType::TimeTime,
                            row.try_get::<Option<Vec<time::Time>>, _>(c.ordinal())
                                .expect("Failed to get timetz array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::TimeTime(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        #[cfg(feature = "with-uuid")]
                        "UUID" => Value::Uuid(
                            row.try_get::<Option<uuid::Uuid>, _>(c.ordinal())
                                .expect("Failed to get uuid"),
                        ),

                        #[cfg(all(feature = "with-uuid", feature = "postgres-array"))]
                        "UUID[]" => Value::Array(
                            sea_query::ArrayType::Uuid,
                            row.try_get::<Option<Vec<uuid::Uuid>>, _>(c.ordinal())
                                .expect("Failed to get uuid array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::Uuid(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

                        _ => unreachable!("Unknown column type: {}", c.type_info().name()),
                    },

View on GitHub (pinned to e29bcd1b41)