SeaQL/sea-orm · error

Failed to get ip address

Error message

Failed to get ip address

What it means

This panic fires when sea-orm's Postgres driver cannot decode an INET or CIDR column into Option<ipnetwork::IpNetwork> (requires `with-ipnetwork`). try_get fails when the cell isn't actually inet/cidr on the wire (e.g. text from a cast), NULL cannot map through the Option path, or sqlx was built without ipnetwork support. The `.expect` turns the sqlx error into a panic in ProxyDecodedRow conversion.

Source

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

                            any(feature = "json-array", feature = "postgres-array")
                        ))]
                        "JSON[]" | "JSONB[]" => Value::Array(
                            sea_query::ArrayType::Json,
                            row.try_get::<Option<Vec<serde_json::Value>>, _>(c.ordinal())
                                .expect("Failed to get json array")
                                .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())

View on GitHub (pinned to e29bcd1b41)

Solutions

  1. Remove casts on the IP column so the wire type stays inet/cidr (`SELECT client_ip` not `client_ip::text`).
  2. Verify with `SELECT pg_typeof(col)` that the column really is inet or cidr.
  3. Enable `with-ipnetwork` consistently on sea-orm across the workspace and align the sqlx version.
  4. If the column is text in the schema, either migrate it to inet or change the entity field type.

Example fix

// before
SELECT client_ip::text FROM sessions;

// after
SELECT client_ip FROM sessions;
Defensive patterns

Strategy: validation

Validate before calling

// Verify the column is inet/cidr before decoding as IpNetwork:
let t = db.query_one(Statement::from_string(
    DatabaseBackend::Postgres,
    "SELECT pg_typeof(client_ip)::text FROM sessions LIMIT 1",
)).await?;
// expect "inet" or "cidr"

Try / catch

// Decode defensively as text and parse with std::net where the schema is uncertain:
let raw = db.query_all(Statement::from_string(
    DatabaseBackend::Postgres,
    "SELECT client_ip::text FROM sessions",
)).await?;
let ip: Option<ipnetwork::IpNetwork> = raw[0]
    .try_get::<Option<String>, _>(0)?
    .and_then(|s| s.parse().ok());

Prevention

When it happens

Trigger: Selecting an inet/cidr column from a raw query where the driver reports a different type (host() or text casts), or with feature/version mismatch between sea-orm's with-ipnetwork branch and the linked sqlx build lacking the ipnetwork decoder.

Common situations: Reading audit/connection tables storing client IPs; queries like `SELECT client_ip::text` fetched through an entity typed as IpNetwork; workspace crates with inconsistent with-ipnetwork flags.

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