{"record":{"id":"f43f69fd3c535f16","repo":"dbt-labs/dbt-core","slug":"adapter-must-be-configured-for-the-parse-phase","errorCode":null,"errorMessage":"Adapter must be configured for the parse phase","messagePattern":"Adapter must be configured for the parse phase","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-parser/src/renderer.rs","lineNumber":966,"sourceCode":"            .out_dir\n            .join(&model.common().original_file_path)\n            .exists()\n        {\n            PathBuf::from(DBT_TARGET_DIR_NAME).join(&model.common().original_file_path)\n        } else {\n            arg.io.in_dir.join(&model.common().original_file_path)\n        };\n        // TODO: Potentially catch rendering warning on second pass and notify user / add file as unsafe by default\n        let _res = render_sql(\n            &sql,\n            jinja_env,\n            &render_resolved_context,\n            &DefaultRenderingEventListenerFactory::default(),\n            &display_path,\n        );\n        let is_unsafe = parse_adapter\n            .parse_adapter_state()\n            .expect(\"Adapter must be configured for the parse phase\")\n            .unsafe_nodes()\n            .contains(&model.common().unique_id);\n        nodes.push((model, is_unsafe));\n    }\n    Ok(nodes)\n}\n\nfn chunk_vec<T>(mut v: Vec<T>, chunk_size: usize) -> Vec<Vec<T>> {\n    let mut chunks = Vec::new();\n    while !v.is_empty() {\n        let chunk: Vec<T> = v.drain(..chunk_size.min(v.len())).collect();\n        chunks.push(chunk);\n    }\n    chunks\n}\n\n/// Collect refs and sources from pre and post hooks in any resource config\n/// by rendering them into the existing sql_resources collection","sourceCodeStart":948,"sourceCodeEnd":984,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-parser/src/renderer.rs#L948-L984","documentation":"A panic from `.expect()` in `process_model_chunk_for_unsafe_detection` (called from `collect_adapter_identifiers_detect_unsafe`). After rendering a model chunk, the code queries the parse adapter's state to check `unsafe_nodes()`; if the adapter has no parse-phase state configured, the expect panics. Like its sibling, this asserts the adapter was fully initialized (not just present) for the parse phase.","triggerScenarios":"Model chunk processing during unsafe-node detection when `parse_adapter.parse_adapter_state()` returns None — the adapter object exists in the env but was never given a `ParseAdapterState`.","commonSituations":"Custom adapters or test harnesses that call `set_adapter` but skip parse-state initialization; partial migration after crate upgrades changed how parse state is attached.","solutions":["Initialize the parse adapter state (`set_parse_adapter_state`) before running resolution","Use the built-in parse entry points rather than invoking chunk processors directly","Ensure the adapter implementation forwards the parse-state methods required by dbt-parser","Update custom adapter scaffolding to match the current parse-phase setup API"],"exampleFix":"// before\njinja_env.set_adapter(adapter.clone());\nprocess_model_chunk_for_unsafe_detection(...); // panics: no parse state\n\n// after\njinja_env.set_adapter(adapter.clone());\nadapter.set_parse_adapter_state(ParseAdapterState::default());\nprocess_model_chunk_for_unsafe_detection(...);","handlingStrategy":"validation","validationCode":"if adapter.parse_adapter_state().is_none() {\n    return Err(\"adapter parse state must be initialized before chunk processing\".into());\n}","typeGuard":"fn parse_state_ready(adapter: &ParseAdapter) -> bool {\n    adapter.parse_adapter_state().is_some()\n}","tryCatchPattern":null,"preventionTips":["Initialize ParseAdapterState immediately after set_adapter","Keep custom adapter scaffolding updated with the parse-phase setup API","Add an integration smoke test that runs unsafe-node detection end to end"],"tags":["rust","adapter","parse-phase","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}