{"record":{"id":"ec38de91cdeaf4f1","repo":"SeaQL/sea-orm","slug":"failed-to-get-ip-address-ec38de","errorCode":null,"errorMessage":"Failed to get ip address","messagePattern":"Failed to get ip address","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/driver/sqlx_postgres.rs","lineNumber":679,"sourceCode":"                            any(feature = \"json-array\", feature = \"postgres-array\")\n                        ))]\n                        \"JSON[]\" | \"JSONB[]\" => Value::Array(\n                            sea_query::ArrayType::Json,\n                            row.try_get::<Option<Vec<serde_json::Value>>, _>(c.ordinal())\n                                .expect(\"Failed to get json array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::Json(Some(Box::new(val))))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-ipnetwork\")]\n                        \"INET\" | \"CIDR\" => Value::IpNetwork(\n                            row.try_get::<Option<ipnetwork::IpNetwork>, _>(c.ordinal())\n                                .expect(\"Failed to get ip address\"),\n                        ),\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())","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/driver/sqlx_postgres.rs#L661-L697","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\n.expect(\"Failed to get ip address\")\n// after\n.map_err(|e| DbErr::TryIntoError { value_type: \"ipnetwork\".into(), source: e.into() })?","handlingStrategy":"validation","validationCode":"let udt: (String,) = sqlx::query_as(\n    \"SELECT udt_name FROM information_schema.columns WHERE table_name=$1 AND column_name=$2\",\n)\n.bind(\"my_table\").bind(\"ip\").fetch_one(&pool).await?;\nassert!(matches!(udt.0.as_str(), \"inet\" | \"cidr\"), \"not inet/cidr: {}\", udt.0);","typeGuard":"fn is_ip_type(udt_name: &str) -> bool { matches!(udt_name, \"inet\" | \"cidr\") }","tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","sqlx","postgres","ipnetwork","panic"],"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"}