SeaQL/sea-orm · error
Failed to get ip address
Error message
Failed to get ip address
What it means
ProxyRow decodes INET/CIDR columns into ipnetwork::IpNetwork with .expect("Failed to get ip address"), panicking when sqlx cannot decode the value. Because the target is Option, NULL is fine; the panic indicates the column's actual wire type is not a Postgres inet/cidr as sqlx understands it, or the with-ipnetwork feature's ipnetwork crate version mismatches sqlx's codec.
Source
Thrown at src/driver/sqlx_postgres.rs:679
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
- Verify the column type is genuinely inet/cidr and fix with ALTER ... TYPE inet USING col::inet.
- Run cargo tree -i ipnetwork and pin a single ipnetwork version matching sqlx's requirement.
- Cast in the query: SELECT my_col::inet AS my_col.
- Propagate the sqlx error (DbErr) instead of .expect in driver code.
Example fix
// before
.expect("Failed to get ip address")
// after
.map_err(|e| DbErr::TryIntoError { value_type: "ipnetwork".into(), source: e.into() })? Defensive patterns
Strategy: validation
Validate before calling
let udt: (String,) = sqlx::query_as(
"SELECT udt_name FROM information_schema.columns WHERE table_name=$1 AND column_name=$2",
)
.bind("my_table").bind("ip").fetch_one(&pool).await?;
assert!(matches!(udt.0.as_str(), "inet" | "cidr"), "not inet/cidr: {}", udt.0); Type guard
fn is_ip_type(udt_name: &str) -> bool { matches!(udt_name, "inet" | "cidr") } Prevention
- Define address columns as inet/cidr, not varchar
- Keep exactly one ipnetwork crate version (cargo tree -i ipnetwork)
- Enable the with-ipnetwork feature on both sea-orm and sqlx consistently
- Prefer IP validation at write time so values are canonical inet
When it happens
Trigger: Selecting a column typed "INET"/"CIDR" by name when the value is stored as text/varchar, or when the ipnetwork version in the tree differs from the one sqlx implements FromSql for (two ipnetwork versions in Cargo.lock).
Common situations: Columns defined as varchar holding IP strings that a migration renamed to inet semantics; duplicate ipnetwork crate versions after dependency updates; reading through a view returning text.
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
- Failed to get uuid
- Failed to get uuid array
- Failed to get oid
- Failed to get oid array
- Failed to get json
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/ec38de91cdeaf4f1.
Report an issue: GitHub.