SeaQL/sea-orm · error

Failed to get mac address array

Error message

Failed to get mac address array

What it means

This panic is raised when sea-orm cannot decode a MACADDR[]/MACADDR8[] array column into Option<Vec<mac_address::MacAddress>> (requires `with-mac_address` and `postgres-array`). try_get fails when the value is not a recognized macaddr array (e.g. text[]), the element type OID is unsupported by the linked sqlx, or feature flags are inconsistent between sea-orm and sqlx. The `.expect` escalates the decode error into a panic during row conversion.

Source

Thrown at sea-orm-sync/src/driver/sqlx_postgres.rs:691

                                .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. Check the type with `SELECT pg_typeof(col)` and cast explicitly: `SELECT col::macaddr[] FROM t`.
  2. Migrate text[] columns to macaddr[]: `ALTER TABLE t ALTER col TYPE macaddr[] USING col::macaddr[]`.
  3. Enable `with-mac_address` and `postgres-array` together on sea-orm in all crates and align the sqlx version.
  4. Update sqlx/sea-orm if your pinned version lacks macaddr array element support.

Example fix

// before
SELECT macs FROM nics; -- macs is text[]

// after
SELECT macs::macaddr[] AS macs FROM nics;
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the column is a true macaddr[] array:
let t = db.query_one(Statement::from_string(
    DatabaseBackend::Postgres,
    "SELECT format_type(a.atttypid, a.atttypmod) FROM pg_attribute a WHERE a.attrelid = 'nics'::regclass AND a.attname = 'macs'",
)).await?;
// expect "macaddr[]"

Try / catch

// Fall back to text[] plus parse when the schema is text-based:
let rows = db.query_all(Statement::from_string(
    DatabaseBackend::Postgres,
    "SELECT macs::text[] FROM nics",
)).await?;
let macs: Vec<mac_address::MacAddress> = rows[0].try_get::<Vec<String>, _>(0)?
    .into_iter()
    .map(|s| s.parse())
    .collect::<Result<_, _>>()?;

Prevention

When it happens

Trigger: Selecting a macaddr[] column whose actual type is text[] or which was cast in SQL, or compiling sea-orm's mac-address array branch against an sqlx build missing the MacAddress array FromSql impl.

Common situations: Device tables storing multiple interface MACs in text[] later modeled as typed arrays; array_agg over macaddr in old Postgres versions returning text[]; feature-flag drift between workspace crates.

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