{"record":{"id":"61312b9c0bc52b72","repo":"SeaQL/sea-orm","slug":"failed-to-get-json-61312b","errorCode":null,"errorMessage":"Failed to get json","messagePattern":"Failed to get json","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sea-orm-sync/src/driver/sqlx_postgres.rs","lineNumber":643,"sourceCode":"                        }\n                        #[cfg(feature = \"postgres-array\")]\n                        \"OID[]\" => Value::Array(\n                            sea_query::ArrayType::BigInt,\n                            row.try_get::<Option<Vec<i64>>, _>(c.ordinal())\n                                .expect(\"Failed to get oid array\")\n                                .map(|vals| {\n                                    Box::new(\n                                        vals.into_iter()\n                                            .map(|val| Value::BigInt(Some(val)))\n                                            .collect(),\n                                    )\n                                }),\n                        ),\n\n                        #[cfg(feature = \"with-json\")]\n                        \"JSON\" | \"JSONB\" => Value::Json(\n                            row.try_get::<Option<serde_json::Value>, _>(c.ordinal())\n                                .expect(\"Failed to get json\")\n                                .map(Box::new),\n                        ),\n                        #[cfg(all(\n                            feature = \"with-json\",\n                            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                        ),","sourceCodeStart":625,"sourceCodeEnd":661,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/driver/sqlx_postgres.rs#L625-L661","documentation":"This panic occurs when sea-orm's Postgres driver cannot decode a JSON/JSONB column into Option<serde_json::Value> (requires `with-json`). try_get fails when the cell is not actually json/jsonb on the wire (e.g. it is text), or the sqlx build lacks json support so the decode is rejected. Because the code uses `.expect`, the failure is a panic instead of a returned error.","triggerScenarios":"Selecting a JSON/JSONB column via raw SQL where the driver returns the type under a different name (e.g. from a view or a `to_jsonb(...)` in a context that yields text), or with the `with-json` feature disabled in the sqlx dependency while sea-orm compiled the JSON branch, or deserializing from a connection built with mismatched feature sets.","commonSituations":"Feature-flag drift between sea-orm and sqlx in the workspace (one crate enables with-json, another doesn't); reading JSON columns through UNION/CASE expressions where Postgres infers text; older sqlx versions with jsonb decoding bugs.","solutions":["Ensure the `with-json` feature is enabled consistently on sea-orm and that the sqlx version it pulls supports json decoding.","Verify the column type with `SELECT pg_typeof(col)`; cast explicitly if a query returns text: `col::jsonb`.","Avoid UNION/CASE mixes that downgrade jsonb to text; cast each branch to jsonb.","Run `cargo tree -i sqlx` to confirm a single sqlx version with the json feature is linked."],"exampleFix":"// before\nSELECT CASE WHEN ok THEN data ELSE 'null' END AS data FROM t;\n\n// after\nSELECT CASE WHEN ok THEN data ELSE 'null'::jsonb END::jsonb AS data FROM t;","handlingStrategy":"validation","validationCode":"// Check that the JSON feature set is coherent and the column is really json/jsonb:\nlet t = db.query_one(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT pg_typeof(data)::text FROM t LIMIT 1\",\n)).await?;\n// expect \"json\" or \"jsonb\"","typeGuard":null,"tryCatchPattern":"// Since this is a panic, avoid it by decoding nullable-json via raw SQL with an explicit cast:\nlet rows = db.query_all(Statement::from_string(\n    DatabaseBackend::Postgres,\n    \"SELECT data::jsonb FROM t\",\n)).await?;\n// then try_get::<Option<serde_json::Value>, _>(0)? returns a Result you can handle.","preventionTips":["Enable with-json on sea-orm in every workspace crate so a single coherent sqlx build is linked.","Run `cargo tree -d` to detect duplicate sqlx versions with different features.","Cast CASE/UNION branches to jsonb to prevent type downgrade to text.","Declare entity columns as Json only when the DB column is json/jsonb."],"tags":["postgres","json","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"}