dbt-labs/dbt-core · error
Adapter must be configured for the parse phase
Error message
Adapter must be configured for the parse phase
What it means
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.
Source
Thrown at crates/dbt-parser/src/renderer.rs:966
.out_dir
.join(&model.common().original_file_path)
.exists()
{
PathBuf::from(DBT_TARGET_DIR_NAME).join(&model.common().original_file_path)
} else {
arg.io.in_dir.join(&model.common().original_file_path)
};
// TODO: Potentially catch rendering warning on second pass and notify user / add file as unsafe by default
let _res = render_sql(
&sql,
jinja_env,
&render_resolved_context,
&DefaultRenderingEventListenerFactory::default(),
&display_path,
);
let is_unsafe = parse_adapter
.parse_adapter_state()
.expect("Adapter must be configured for the parse phase")
.unsafe_nodes()
.contains(&model.common().unique_id);
nodes.push((model, is_unsafe));
}
Ok(nodes)
}
fn chunk_vec<T>(mut v: Vec<T>, chunk_size: usize) -> Vec<Vec<T>> {
let mut chunks = Vec::new();
while !v.is_empty() {
let chunk: Vec<T> = v.drain(..chunk_size.min(v.len())).collect();
chunks.push(chunk);
}
chunks
}
/// Collect refs and sources from pre and post hooks in any resource config
/// by rendering them into the existing sql_resources collectionView on GitHub (pinned to 0267ce9170)
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
Example fix
// before jinja_env.set_adapter(adapter.clone()); process_model_chunk_for_unsafe_detection(...); // panics: no parse state // after jinja_env.set_adapter(adapter.clone()); adapter.set_parse_adapter_state(ParseAdapterState::default()); process_model_chunk_for_unsafe_detection(...);
Defensive patterns
Strategy: validation
Validate before calling
if adapter.parse_adapter_state().is_none() {
return Err("adapter parse state must be initialized before chunk processing".into());
} Type guard
fn parse_state_ready(adapter: &ParseAdapter) -> bool {
adapter.parse_adapter_state().is_some()
} Prevention
- 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
When it happens
Trigger: 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`.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/f43f69fd3c535f16.
Report an issue: GitHub.