{"record":{"id":"bc75e9a9c9cc06d6","repo":"dbt-labs/dbt-core","slug":"clean-sql","errorCode":null,"errorMessage":"clean_sql","messagePattern":"clean_sql","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbt-adapter/src/adapter/mod.rs","lineNumber":3593,"sourceCode":"            }\n            Parse(_) => Ok(none_value()),\n        }\n    }\n\n    /// Clean SQL by removing extra whitespace and normalizing format.\n    ///\n    /// Only available with Databricks adapter.\n    #[tracing::instrument(skip_all, level = \"trace\")]\n    pub fn clean_sql(&self, _state: &State, args: &[Value]) -> Result<Value, minijinja::Error> {\n        match &self.inner {\n            Typed { adapter, .. } => {\n                let iter = ArgsIter::new(\"clean_sql\", &[\"sql\"], args);\n                let sql = iter.next_arg::<&str>()?;\n                iter.finish()?;\n\n                Ok(Value::from(adapter.clean_sql(sql)?))\n            }\n            Parse(_) => unimplemented!(\"clean_sql\"),\n        }\n    }\n\n    /// Used internally to attempt executing a Snowflake `use warehouse [name]` statement.\n    #[tracing::instrument(skip(self), level = \"trace\")]\n    pub fn use_warehouse(\n        &self,\n        warehouse: Option<String>,\n        node_id: &str,\n    ) -> FsResult<Option<NodeOverride>> {\n        // TODO(jason): Record/replay non-jinja internal calls non-invasively\n        // https://github.com/dbt-labs/fs/issues/7736\n        if let Some(tm) = self.time_machine()\n            && tm.is_replaying()\n        {\n            return Ok(None);\n        }\n","sourceCodeStart":3575,"sourceCodeEnd":3611,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-adapter/src/adapter/mod.rs#L3575-L3611","documentation":"The `clean_sql` adapter method is available on concrete (typed/execution) adapters but not on the Parse adapter; calling it while the inner adapter is the `Parse` variant panics with `unimplemented!(\"clean_sql\")`. During parsing (no database connection), SQL-cleaning operations that require the adapter's dialect runtime are unavailable. It reflects invoking an execution-time method during the parse phase of the dbt lifecycle.","triggerScenarios":"Calling `adapter.clean_sql(sql)` from a macro or internal code while the Adapter wraps the Parse engine — i.e. during the parse/compile phase before a real adapter is attached.","commonSituations":"Macros that run during parsing but call clean_sql; dbt parse (`dbt parse`) or partial-parse runs hitting macros that assume a live connection; custom materializations invoking clean_sql unconditionally.","solutions":["Move the clean_sql call into code that only executes during execution (not parse), e.g. guard with execute check (`{% if execute %}`).","Skip SQL cleaning during parse — return the SQL unmodified when the adapter is a Parse adapter.","Check whether the macro should be in a parse-time block at all; parse-time code must avoid adapter runtime methods."],"exampleFix":"// before\n{% set cleaned = adapter.clean_sql(sql) %}\n// after\n{% if execute %}\n  {% set cleaned = adapter.clean_sql(sql) %}\n{% else %}\n  {% set cleaned = sql %}\n{% endif %}","handlingStrategy":"validation","validationCode":"// Jinja: only call clean_sql during execution\n{% set can_clean = execute %}","typeGuard":"{% if execute %} ... {% endif %} — 'execute' is false during parse, true at runtime.","tryCatchPattern":"// Parse-time code must not call clean_sql\n{% if execute %}\n  {% set cleaned = adapter.clean_sql(sql) %}\n{% else %}\n  {% set cleaned = sql %}\n{% endif %}","preventionTips":["Wrap adapter runtime methods in `{% if execute %}` blocks","Test macros with `dbt parse` to catch parse-phase misuse","Never call connection-dependent adapter methods from parse-time contexts"],"tags":["unimplemented","parse","adapter","sql"],"backgroundTag":"operation-not-supported","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}