SeaQL/sea-orm · error

Failed to get mac address array

Error message

Failed to get mac address array

What it means

For MACADDR[]/MACADDR8[] columns, ProxyRow calls row.try_get::<Option<Vec<mac_address::MacAddress>>, _> with .expect("Failed to get mac address array"), panicking on sqlx decode failure. The value is not decodable as an array of MacAddress — the wire type differs from macaddr[]/macaddr8[] or the mac_address codec version mismatches sqlx.

Source

Thrown at src/driver/sqlx_postgres.rs:704

                                .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())
                                .expect("Failed to get timestamp"),
                        ),
                        #[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"),

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Verify udt_name is _macaddr/_macaddr8 and ALTER to a genuine macaddr[] otherwise.
  2. Unify mac_address crate versions with cargo tree -i mac_address.
  3. Cast in SQL: SELECT my_col::macaddr[] AS my_col.
  4. Propagate the decode error as DbErr instead of panicking.

Example fix

// before
.expect("Failed to get mac address array")
// 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("macs").fetch_one(&pool).await?;
assert!(udt.0 == "_macaddr" || udt.0 == "_macaddr8", "not a macaddr[]: {}", udt.0);

Type guard

fn is_mac_array(udt_name: &str) -> bool { matches!(udt_name, "_macaddr" | "_macaddr8") }

Prevention

When it happens

Trigger: Selecting a column reported as "MACADDR[]" whose value is scalar macaddr, text[], or a domain-over-array; needs both with-mac_address and postgres-array features.

Common situations: Schema drift after migration; views/FDWs reporting wrong element type OIDs; split mac_address crate versions after dependency changes.

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