Skip to content

Error when RenderConfig.invocation_mode is incorrectly set#2267

Merged
tatiana merged 5 commits into
mainfrom
error-incorrect-invocation-mode-set
Jan 14, 2026
Merged

Error when RenderConfig.invocation_mode is incorrectly set#2267
tatiana merged 5 commits into
mainfrom
error-incorrect-invocation-mode-set

Conversation

@tatiana
Copy link
Copy Markdown
Collaborator

@tatiana tatiana commented Jan 14, 2026

Make our configuration validation more robust, to guide users when they misconfigure Cosmos RenderConfig.invocation_mode.

This configuration should only be used if dbt is installed in the same Python virtualenv as Cosmos.

Recently, I observed a customer incorrectly configuring Cosmos as follows:

ExecutionConfig(
  dbt_executable_path=airflowHome + '/dbt_venv/bin/dbt',
  execution_mode=ExecutionMode.WATCHER,
  invocation_mode=InvocationMode.DBT_RUNNER
)

Which led to the error:

ModuleNotFoundError: No module named 'dbt'

This was raised in Cosmos 1.12, when trying to resolve dbt.version

cosmos/operators/watcher.py:_fallback_to_local_run → build_and_run_cmd → _generate_dbt_flags

Copilot AI review requested due to automatic review settings January 14, 2026 15:08
@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 14, 2026

Deploy Preview for astronomer-cosmos canceled.

Name Link
🔨 Latest commit fd15dbe
🔍 Latest deploy log https://app.netlify.com/projects/astronomer-cosmos/deploys/6967d0d812694400081c9a4f

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds validation to prevent users from misconfiguring RenderConfig.invocation_mode when dbt is not installed in the same Python environment as Cosmos. The validation catches cases where users incorrectly set InvocationMode.DBT_RUNNER while using a separate dbt virtualenv, which would lead to ModuleNotFoundError: No module named 'dbt'.

Changes:

  • Added new helper function is_dbt_installed_in_same_environment() to check if dbt is available in the current environment
  • Added validation logic in validate_initial_user_config() to verify dbt installation and executable path when using DBT_RUNNER invocation mode
  • Added comprehensive test coverage for the new validation scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cosmos/dbt/executable.py Added helper function to detect if dbt is installed in the current environment
cosmos/converter.py Added validation to check for dbt installation and executable path compatibility when using DBT_RUNNER mode
tests/test_converter.py Added four test cases covering validation scenarios for DBT_RUNNER configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cosmos/dbt/executable.py Outdated
Comment thread cosmos/converter.py
@tatiana tatiana mentioned this pull request Jan 14, 2026
@tatiana tatiana merged commit 4cfac69 into main Jan 14, 2026
87 checks passed
@tatiana tatiana deleted the error-incorrect-invocation-mode-set branch January 14, 2026 17:43
tatiana added a commit that referenced this pull request Jan 14, 2026
Make our configuration validation more robust, to guide users when they
misconfigure Cosmos `RenderConfig.invocation_mode`.

This configuration should only be used if dbt is installed in the same
Python virtualenv as Cosmos.

Recently, I observed a customer incorrectly configuring Cosmos as
follows:
```
ExecutionConfig(
  dbt_executable_path=airflowHome + '/dbt_venv/bin/dbt',
  execution_mode=ExecutionMode.WATCHER,
  invocation_mode=InvocationMode.DBT_RUNNER
)
```

Which led to the error:
```
ModuleNotFoundError: No module named 'dbt'
```

This was raised in Cosmos 1.12, when trying to resolve `dbt.version`
```
cosmos/operators/watcher.py:_fallback_to_local_run → build_and_run_cmd → _generate_dbt_flags
```

(cherry picked from commit 4cfac69)
tatiana added a commit that referenced this pull request Jan 14, 2026
Bug Fixes

* Fix ``DbtSourceWatcherOperator.template_fields`` to inherit from
``DbtSourceLocalOperator`` instead of ``DbtConsumerWatcherSensor`` by
@pankajkoti in #2226
* Fix TypeError in Watcher mode with subprocess invocation by
@pankajkoti in #2227
* Error when RenderConfig.invocation_mode is incorrectly set by @tatiana
in #2267

Docs

* Fix minor documentation typo by @dnskr in #2093
* Fix default values in documentation by @dnskr in #2092
* Remove emit event for ExecutionMode.AIRFLOW_ASYNC limitation in docs
by @pankajastro in #2214

Others

* Add test to check profile metrics with non-Cosmos operator by
@pankajastro in #2215
* Fix CI main branch Airflow 2.6 tests by @tatiana in #2268

closes:
astronomer/oss-integrations-private#295

Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>
pankajkoti added a commit that referenced this pull request Jan 15, 2026
Following up on PR #2267, fix a typo in the error message suggesting to
use `InvocationMode.SUBPROCESS`

related: #2267
@tatiana tatiana added this to the Cosmos 1.12.1 milestone Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants