SeaQL/sea-orm · error

Failed to get mac address

Error message

Failed to get mac address

What it means

ProxyRow decodes MACADDR/MACADDR8 columns into mac_address::MacAddress with .expect("Failed to get mac address"), panicking when sqlx cannot decode. Option handles NULL, so the panic means the wire value isn't a Postgres macaddr/macaddr8 as sqlx expects, or the mac_address crate version sqlx links differs from the one in the dependency graph.

Source

Thrown at src/driver/sqlx_postgres.rs:698

                        ),
                        #[cfg(feature = "with-ipnetwork")]
                        "INET[]" | "CIDR[]" => Value::Array(
                            sea_query::ArrayType::IpNetwork,
                            row.try_get::<Option<Vec<ipnetwork::IpNetwork>>, _>(c.ordinal())
                                .expect("Failed to get ip address array")
                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::IpNetwork(Some(val)))
                                            .collect(),
                                    )
                                }),
                        ),

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

                        #[cfg(feature = "with-chrono")]
                        "TIMESTAMP" => Value::ChronoDateTime(
                            row.try_get::<Option<chrono::NaiveDateTime>, _>(c.ordinal())

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Check the column type is real macaddr/macaddr8 and ALTER ... TYPE macaddr USING col::macaddr if not.
  2. Run cargo tree -i mac_address and unify to a single version sqlx supports.
  3. Cast in the query: SELECT my_col::macaddr AS my_col.
  4. Map the sqlx error to DbErr instead of .expect in driver code.

Example fix

// before
.expect("Failed to get mac address")
// after
.map_err(|e| DbErr::TryIntoError { value_type: "mac_address".into(), source: e.into() })?
Defensive patterns

Strategy: validation

Validate before calling

let udt: (String,) = sqlx::query_as(
    "SELECT udt_name FROM information_schema.columns WHERE table_name=$1 AND column_name=$2",
)
.bind("my_table").bind("mac").fetch_one(&pool).await?;
assert!(matches!(udt.0.as_str(), "macaddr" | "macaddr8"), "not macaddr: {}", udt.0);

Type guard

fn is_mac_type(udt_name: &str) -> bool { matches!(udt_name, "macaddr" | "macaddr8") }

Prevention

When it happens

Trigger: Selecting a column typed "MACADDR"/"MACADDR8" whose value is stored as text, or a duplicate mac_address crate version breaking FromSql impl matching; requires the with-mac_address feature.

Common situations: varchar columns holding MAC strings; Cargo.lock with two mac_address versions after update; reading via a view that returns text.

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