{"record":{"id":"7351b78f0ccb6fac","repo":"SeaQL/sea-orm","slug":"failed-to-get-mac-address","errorCode":null,"errorMessage":"Failed to get mac address","messagePattern":"Failed to get mac address","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":685,"sourceCode":"                        ),\n                        #[cfg(feature = \"with-ipnetwork\")]\n                        \"INET[]\" | \"CIDR[]\" => Value::Array(\n                            sea_query::ArrayType::IpNetwork,\n                            row.try_get::<Option<Vec<ipnetwork::IpNetwork>>, _>(c.ordinal())\n                                .expect(\"Failed to get ip address array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::IpNetwork(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-mac_address\")]\n                        \"MACADDR\" | \"MACADDR8\" => Value::MacAddress(\n                            row.try_get::<Option<mac_address::MacAddress>, _>(c.ordinal())\n                                .expect(\"Failed to get mac address\"),\n                        ),\n                        #[cfg(all(feature = \"with-mac_address\", feature = \"postgres-array\"))]\n                        \"MACADDR[]\" | \"MACADDR8[]\" => Value::Array(\n                            sea_query::ArrayType::MacAddress,\n                            row.try_get::<Option<Vec<mac_address::MacAddress>>, _>(c.ordinal())\n                                .expect(\"Failed to get mac address array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::MacAddress(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-chrono\")]\n                        \"TIMESTAMP\" => Value::ChronoDateTime(\n                            row.try_get::<Option<chrono::NaiveDateTime>, _>(c.ordinal())","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L667-L703","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove SQL casts/formatting on the macaddr column so the returned type is macaddr.","Verify the column type with `SELECT pg_typeof(col)`; if it's text, migrate the column or change the model type to String.","Enable `with-mac_address` consistently on sea-orm everywhere and keep the sqlx version aligned.","Cast explicitly to macaddr when a CASE/UNION downgrades the type: `col::macaddr`."],"exampleFix":"// before\nSELECT replace(mac::text, ':', '-') AS mac FROM devices;\n\n// after\nSELECT mac FROM devices;","handlingStrategy":"validation","validationCode":"// Verify the column is macaddr before decoding as MacAddress:\nlet t = db.query_one(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT pg_typeof(mac)::text FROM devices LIMIT 1\",\n)).await?;\n// expect \"macaddr\" or \"macaddr8\"","typeGuard":null,"tryCatchPattern":"// Decode as text and parse manually when the storage type is text:\nlet raw = db.query_all(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT mac::text FROM devices\",\n)).await?;\nlet macs: Vec<mac_address::MacAddress> = raw.iter()\n    .filter_map(|r| r.try_get::<Option<String>, _>(0).ok().flatten())\n    .filter_map(|s| s.parse().ok())\n    .collect();","preventionTips":["Use macaddr/macaddr8 storage types and avoid text casts in fetched queries.","Enable with-mac_address consistently across workspace crates.","Format MACs in application code, not in the SELECT list.","Verify `pg_typeof` when mapping views or computed columns to entities."],"tags":["postgres","mac-address","type-decoding","panic","sea-orm"],"backgroundTag":"type-mismatch","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}