SeaQL/sea-orm · error

Failed to get ip address array

Error message

Failed to get ip address array

What it means

This panic is raised when sea-orm cannot decode an INET[]/CIDR[] array column into Option<Vec<ipnetwork::IpNetwork>> (requires `with-ipnetwork`). try_get fails when the value is not a recognized inet/cidr array (e.g. it's text[]), an element type is unsupported, or the sqlx build lacks array support for these types. The `.expect` escalates to a panic during row decoding.

Source

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

                                .map(|vals| {
                                    Box::new(
                                        vals.into_iter()
                                            .map(|val| Value::Json(Some(Box::new(val))))
                                            .collect(),
                                    )
                                }),
                        ),

                        #[cfg(feature = "with-ipnetwork")]
                        "INET" | "CIDR" => Value::IpNetwork(
                            row.try_get::<Option<ipnetwork::IpNetwork>, _>(c.ordinal())
                                .expect("Failed to get ip address"),
                        ),
                        #[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())

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Check the real type with `SELECT pg_typeof(col)` and cast explicitly: `SELECT col::inet[] FROM t`.
  2. Migrate text[] columns storing IPs to inet[]: `ALTER TABLE t ALTER col TYPE inet[] USING col::inet[]`.
  3. Enable `with-ipnetwork` and `postgres-array` together on sea-orm in all workspace crates.
  4. Update sqlx/sea-orm if the inet array element type is not supported in your pinned versions.

Example fix

// before
SELECT allowlist FROM firewall; -- allowlist is text[]

// after
SELECT allowlist::inet[] AS allowlist FROM firewall;
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the column is a true inet[]/cidr[] 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 = 'firewall'::regclass AND a.attname = 'allowlist'",
)).await?;
// expect "inet[]"

Try / catch

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

Prevention

When it happens

Trigger: Selecting an inet[] column while the actual column is text[] or the query cast it, or the `postgres-array`/`with-ipnetwork` features are inconsistently compiled between sea-orm and sqlx so the array decoder isn't present.

Common situations: IP allow-list tables using text[] that were later modeled as IpNetwork arrays; raw SQL with array_agg returning text[]; feature-flag drift after adding postgres-array in only some 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/585e405662eaa6d9. Report an issue: GitHub.