{"record":{"id":"eba285db74ebdde3","repo":"dbt-labs/dbt-core","slug":"adapter-not-found-in-context","errorCode":null,"errorMessage":"adapter not found in context","messagePattern":"adapter not found in context","errorType":"exception","errorClass":"minijinja::Error (UndefinedError)","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/phases/run/run_node_context.rs","lineNumber":819,"sourceCode":"            Error::new(\n                ErrorKind::InvalidOperation,\n                \"compiled_code must be a string\",\n            )\n        })?;\n\n        // Note(Ani):\n        // dbt-core validates:\n        //   - macro_stack.depth == 2\n        //   - call_stack[1] == \"macro.dbt.statement\"\n        //   - \"materialization\" in call_stack[0]\n        //\n        // In fusion, we shouldn't need to do this because this funciton is only registered in the run node context\n        // so if a user tries to use it outside of a statement.sql macro, in a materialization macro, it will fail earlier due to an unrecongized function call.\n\n        // Get adapter from context and call submit_python_job\n        let adapter = state\n            .lookup(\"adapter\", &[])\n            .ok_or_else(|| Error::new(ErrorKind::UndefinedError, \"adapter not found in context\"))?;\n        adapter.call_method(\n            state,\n            \"submit_python_job\",\n            &[parsed_model.clone(), MinijinjaValue::from(compiled_code)],\n            &[],\n        )\n    }\n}\n","sourceCodeStart":801,"sourceCodeEnd":828,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/phases/run/run_node_context.rs#L801-L828","documentation":"Inside `submit_python_job`, the actual work is delegated to the `adapter` object looked up from the Jinja state. This `UndefinedError` is raised when no `adapter` is present in the current context, meaning the function was evaluated in a context where the adapter was never injected. The code comment notes this should only be reachable outside the run-node statement context, where the call would normally fail earlier as an unrecognized function.","triggerScenarios":"Calling `submit_python_job` in a context built without the adapter binding — e.g. during parse phases, in a macro evaluated outside `statement.sql`, or in a context where `extend_base_context_stateful_fn`/`build_run_node_overlay` did not register `adapter`.","commonSituations":"Using `submit_python_job` in dbt_docs or analysis contexts; invoking it from a materialization macro rather than statement.sql; running with an adapter plugin missing so the adapter binding was never registered.","solutions":["Only call `submit_python_job` inside a run-node statement context (statement.sql for python models), not in materialization or other macros.","Ensure the correct adapter is installed and selected so `adapter` is registered in the run node context.","If hit in a custom macro, move the call into the model's compiled code/statement context instead."],"exampleFix":"-- before (materialization macro)\n{% do submit_python_job(model, code) %}\n-- after (statement.sql context of a python model)\n-- invoke via the standard python model execution path instead of calling it directly in a macro\n","handlingStrategy":"try-catch","validationCode":"{# only call submit_python_job inside statement.sql / python model execution context #}\n{% if 'adapter' not in context %}\n  {{ exceptions.raise_compiler_error('submit_python_job requires the run node adapter context') }}\n{% endif %}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"adapter not found in context\") => {\n        // wrong phase/context: reroute the call into statement.sql execution\n    }\n    other => other,\n}","preventionTips":["Only use submit_python_job in python model statement contexts, never in materialization macros.","Verify the adapter plugin is installed so `adapter` is registered.","Keep calls inside statement.sql rather than shared macros."],"tags":["jinja","context","adapter"],"backgroundTag":"resource-not-found","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"}