dbt-labs/dbt-core · error
query addition to connection in MockAdapter
Error message
query addition to connection in MockAdapter
What it means
AdapterImpl::add_query panics when the adapter is a MockAdapter (mock_state().is_some()) and an executable query is added to its connection. MockAdapter is intended for parsing/planning without a real database, so executing SQL against it is unsupported by design.
Source
Thrown at crates/dbt-adapter/src/adapter/adapter_impl.rs:960
token,
)
}
/// SQLAdapter https://github.com/dbt-labs/dbt-adapters/blob/0efd8d3d1081e1ab43e38797d5104f7b424a6284/dbt-adapters/src/dbt/adapters/sql/impl.py#L55
/// BigQueryAdapter https://github.com/dbt-labs/dbt-adapters/blob/0efd8d3d1081e1ab43e38797d5104f7b424a6284/dbt-bigquery/src/dbt/adapters/bigquery/impl.py#L573
#[allow(clippy::too_many_arguments)]
pub fn add_query(
&self,
state: &State,
conn: &'_ mut dyn Connection,
sql: &str,
auto_begin: bool,
bindings: Option<&Value>,
abridge_sql_log: bool,
token: CancellationToken,
) -> AdapterResult<()> {
if self.mock_state().is_some() {
unimplemented!("query addition to connection in MockAdapter")
}
let sql = if let Some(bindings) = bindings {
Cow::Owned(format_sql_with_bindings(
self.adapter_type(),
sql,
bindings,
)?)
} else {
Cow::Borrowed(sql)
};
let ctx = query_ctx_from_state(state)?.with_desc("add_query adapter call");
match self.inner_adapter() {
Replay(_, replay) => replay.replay_add_query(
&ctx,
conn,
sql.as_ref(),
auto_begin,
bindings,View on GitHub (pinned to 0267ce9170)
Solutions
- Use a real database-backed adapter (DuckDB, Postgres, etc.) whenever SQL execution is expected.
- Audit the calling macro/model so no execute path runs under parse/compile with a mock adapter.
- If MockAdapter should support query logging, implement the mock branch in add_query to record the SQL instead of panicking.
Example fix
// before
if self.mock_state().is_some() {
unimplemented!("query addition to connection in MockAdapter")
}
// after
if let Some(state) = self.mock_state() {
state.record_query(&sql);
return Ok(());
} Defensive patterns
Strategy: validation
Validate before calling
if adapter.is_mock() {
return Err("cannot execute SQL: adapter is in mock mode".into());
} Type guard
fn can_execute(adapter: &AdapterImpl) -> bool { adapter.mock_state().is_none() } Prevention
- Only use MockAdapter for parse/compile; use a real adapter (e.g. DuckDB) for run/execute
- Assert execution paths never run under `dbt parse` in CI
- Add a capability check before invoking add_query
When it happens
Trigger: Calling add_query (execute/bind SQL with auto_begin, bindings, cancellation token) on an adapter constructed in mock mode, e.g. during `dbt parse` flows or tests that later reach a code path that executes SQL.
Common situations: Running `dbt compile`/`parse` with a mock adapter while a macro or model invokes execute()/run_query; unit tests that accidentally use MockAdapter for execution paths.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- type conversion from table column in MockAdapter
- load_dataframe() for the Salesforce adapter
- Starburst
- Athena
- Trino
AI-assisted analysis of dbt-labs/dbt-core@0267ce9170 (2026-09-07).
Data as JSON: /api/errors/8d6a1b97b76e8fee.
Report an issue: GitHub.