{"record":{"id":"545eb2a86cfa768a","repo":"SeaQL/sea-orm","slug":"failed-to-get-ip-address","errorCode":null,"errorMessage":"Failed to get ip address","messagePattern":"Failed to get ip address","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":666,"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":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L648-L684","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Remove casts on the IP column so the wire type stays inet/cidr (`SELECT client_ip` not `client_ip::text`).","Verify with `SELECT pg_typeof(col)` that the column really is inet or cidr.","Enable `with-ipnetwork` consistently on sea-orm across the workspace and align the sqlx version.","If the column is text in the schema, either migrate it to inet or change the entity field type."],"exampleFix":"// before\nSELECT client_ip::text FROM sessions;\n\n// after\nSELECT client_ip FROM sessions;","handlingStrategy":"validation","validationCode":"// Verify the column is inet/cidr before decoding as IpNetwork:\nlet t = db.query_one(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT pg_typeof(client_ip)::text FROM sessions LIMIT 1\",\n)).await?;\n// expect \"inet\" or \"cidr\"","typeGuard":null,"tryCatchPattern":"// Decode defensively as text and parse with std::net where the schema is uncertain:\nlet raw = db.query_all(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT client_ip::text FROM sessions\",\n)).await?;\nlet ip: Option<ipnetwork::IpNetwork> = raw[0]\n    .try_get::<Option<String>, _>(0)?\n    .and_then(|s| s.parse().ok());","preventionTips":["Do not cast IP columns to text in queries fetched through entities.","Use inet (not text) as the storage type for IP data.","Enable with-ipnetwork consistently across workspace crates.","Verify `pg_typeof` output when binding views or raw SQL to entity models."],"tags":["postgres","network","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"}