{"record":{"id":"d14e1844ba99edf5","repo":"dbt-labs/dbt-core","slug":"adapter-should-be-configured-for-the-parse-phase","errorCode":null,"errorMessage":"adapter should be configured for the parse phase","messagePattern":"adapter should be configured for the parse phase","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-parser/src/dbt_namespace.rs","lineNumber":60,"sourceCode":"        name: &str,\n        args: &[MinijinjaValue],\n        listeners: &[Rc<dyn RenderingEventListener>],\n    ) -> Result<MinijinjaValue, MinijinjaError> {\n        // Intercept specific method calls to track them\n        match name {\n            \"get_columns_in_relation\" => {\n                // Track the call in the parse adapter\n                // Extract relation from args\n                let relation = args.first().ok_or_else(|| {\n                    MinijinjaError::new(\n                        MinijinjaErrorKind::InvalidOperation,\n                        \"get_columns_in_relation requires one argument\",\n                    )\n                })?;\n                let relation = downcast_value_to_dyn_base_relation(relation)?;\n                self.parse_adapter\n                    .parse_adapter_state()\n                    .expect(\"adapter should be configured for the parse phase\")\n                    .record_get_columns_in_relation_call(state, relation.as_ref())?;\n\n                // Delegate to the original dbt.get_columns_in_relation template\n                let template_name = \"dbt.get_columns_in_relation\";\n                if let Ok(template) = state.env().get_template(template_name) {\n                    let base_ctx = state.get_base_context();\n                    let template_state = template.eval_to_state(base_ctx, listeners)?;\n                    let func = template_state\n                        .lookup(\"get_columns_in_relation\", listeners)\n                        .ok_or_else(|| {\n                            MinijinjaError::new(\n                                MinijinjaErrorKind::InvalidOperation,\n                                \"get_columns_in_relation macro not found\",\n                            )\n                        })?;\n                    func.call(&template_state, args, listeners)\n                } else {\n                    Err(MinijinjaError::new(","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-parser/src/dbt_namespace.rs#L42-L78","documentation":"During parse-phase Jinja method dispatch (`call_method` for `get_columns_in_relation`), the code retrieves the parse-phase adapter state via `parse_adapter_state()` and panics if it is None. The state is installed when the parse adapter is constructed, so a None here means the method was invoked outside the parse phase or before the adapter state was configured.","triggerScenarios":"A dbt template calls `get_columns_in_relation` while the adapter is not in parse phase (e.g. during runtime/execute phase, or an adapter variant whose `parse_adapter_state` was never set before `call_method` runs).","commonSituations":"Custom adapters not wiring up `parse_adapter_state` in their parse-phase construction; macros invoking `get_columns_in_relation` at the wrong phase; version skew between dbt-parser and adapter crates changing the state setup contract.","solutions":["Ensure the adapter is constructed/registered with its parse state during the parse phase","Update adapter and parser crates to matching versions","Move/refrain from calling `get_columns_in_relation` outside parse-phase evaluation","Replace the expect with a proper error reporting the missing phase state"],"exampleFix":"// before\nself.parse_adapter.parse_adapter_state().expect(\"adapter should be configured for the parse phase\")\n// after\nlet state = self.parse_adapter.parse_adapter_state()\n    .ok_or_else(|| format_err!(\"get_columns_in_relation called outside parse phase\"))?;","handlingStrategy":"validation","validationCode":"// guard before calling phase-specific jinja methods\nif adapter.parse_adapter_state().is_none() {\n    return Err(\"get_columns_in_relation requires parse-phase adapter state\".into());\n}","typeGuard":null,"tryCatchPattern":"let Some(state) = self.parse_adapter.parse_adapter_state() else {\n    return Err(format_err!(\"adapter not in parse phase\"));\n};","preventionTips":["Register parse adapter state during parse-phase construction","Keep dbt-parser and adapter crate versions aligned","Avoid invoking get_columns_in_relation outside parse-phase evaluation"],"tags":["adapter","parse-phase","jinja","panic"],"backgroundTag":"invalid-state-transition","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}