SeaQL/sea-orm · error

Failed to get mac address

Error message

Failed to get mac address

What it means

This panic occurs when sea-orm's Postgres driver cannot decode a MACADDR/MACADDR8 column into Option<mac_address::MacAddress> (requires `with-mac_address`). try_get fails if the cell is not actually macaddr on the wire (e.g. text after a cast), NULL cannot map through the decoder, or the linked sqlx build lacks the mac_address decode impl. The `.expect` turns this into a panic instead of a Result error.

Source

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

                        ),
                        #[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. Remove SQL casts/formatting on the macaddr column so the returned type is macaddr.
  2. Verify the column type with `SELECT pg_typeof(col)`; if it's text, migrate the column or change the model type to String.
  3. Enable `with-mac_address` consistently on sea-orm everywhere and keep the sqlx version aligned.
  4. Cast explicitly to macaddr when a CASE/UNION downgrades the type: `col::macaddr`.

Example fix

// before
SELECT replace(mac::text, ':', '-') AS mac FROM devices;

// after
SELECT mac FROM devices;
Defensive patterns

Strategy: validation

Validate before calling

// Verify the column is macaddr before decoding as MacAddress:
let t = db.query_one(Statement::from_string(
    DatabaseBackend::Postgres,
    "SELECT pg_typeof(mac)::text FROM devices LIMIT 1",
)).await?;
// expect "macaddr" or "macaddr8"

Try / catch

// Decode as text and parse manually when the storage type is text:
let raw = db.query_all(Statement::from_string(
    DatabaseBackend::Postgres,
    "SELECT mac::text FROM devices",
)).await?;
let macs: Vec<mac_address::MacAddress> = raw.iter()
    .filter_map(|r| r.try_get::<Option<String>, _>(0).ok().flatten())
    .filter_map(|s| s.parse().ok())
    .collect();

Prevention

When it happens

Trigger: Selecting a macaddr column through a raw query that casts it (`mac::text`, `replace(mac,':','-')`), or reading a text column modeled as MacAddress, or feature/version mismatch where sqlx is compiled without mac_address support while sea-orm enabled the branch.

Common situations: Network device inventory tables; queries that normalize MAC formatting in SQL before fetching; crates enabling with-mac_address on sea-orm but pulling an sqlx version without the integration.

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