Skip to content

Error handle invalid YAML with LoadMode.DBT_MANIFEST and RenderConfig.selector#2316

Merged
tatiana merged 12 commits into
astronomer:mainfrom
YourRoyalLinus:2312-isolate_yaml_selector_parse_errors
Feb 17, 2026
Merged

Error handle invalid YAML with LoadMode.DBT_MANIFEST and RenderConfig.selector#2316
tatiana merged 12 commits into
astronomer:mainfrom
YourRoyalLinus:2312-isolate_yaml_selector_parse_errors

Conversation

@YourRoyalLinus
Copy link
Copy Markdown
Contributor

Description

Ensure that DAG parsing only fails for DAGs that are attempting to render using a misconfigured yaml selector.

This was done by collecting any errors during yaml selector parsing and raising an exception when the selector is accessed rather than when the issue is encountered.

The exception to this is for invalid yaml structures. In those cases, we can't be certain whether we have a valid selector name or definition. When the graph attempts to grab the parsed selector, it would always get a selector not found exception, hiding the error messages related to the invalid structure.

As a result, if there is an invalid yaml structure, all DAGs using LoadMode.DBT_MANIFEST and RenderConfig.selector will fail during dag parse. As long as a user never directly modifies the manifest.json, this should not occur.

When doing local QA, I created separate example DAGs, however keeping them did not seem valuable as the unit tests cover the expected behavior.

Follow up from #2257

Related Issue(s)

closes #2312

Breaking Change?

N/A

Checklist

  • I have made corresponding changes to the documentation (if required)
  • I have added tests that prove my fix is effective or that my feature works

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 2, 2026

Deploy Preview for astronomer-cosmos ready!

Name Link
🔨 Latest commit 988f255
🔍 Latest deploy log https://app.netlify.com/projects/astronomer-cosmos/deploys/698daa24ea75210008456e3d
😎 Deploy Preview https://deploy-preview-2316--astronomer-cosmos.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@YourRoyalLinus YourRoyalLinus marked this pull request as ready for review February 2, 2026 21:47
Copilot AI review requested due to automatic review settings February 2, 2026 21:47
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 improves error handling for YAML selector parsing by deferring most parsing errors until selector access rather than failing immediately at parse time. This ensures that DAG parsing only fails for DAGs actually using a misconfigured selector, while still failing immediately for structural YAML errors that prevent proper selector identification.

Changes:

  • Modified selector parsing to collect errors during parse and raise them on selector access via get_parsed()
  • Updated all parsing methods to return error lists alongside parsed results
  • Added comprehensive test coverage for multiple error scenarios including nested errors and complex selector definitions

Reviewed changes

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

File Description
cosmos/dbt/selector.py Refactored all parsing methods to return tuples including error lists; modified get_parsed() to raise errors when accessing selectors with parsing issues
tests/dbt/test_selector.py Added extensive tests for multi-error scenarios and updated existing tests to call get_parsed() instead of expecting errors from parse()
tests/dbt/test_graph.py Updated selector cache hash value to reflect implementation changes
docs/configuration/selecting-excluding.rst Added documentation explaining the two categories of errors (structural vs definition) and when each is raised

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

Comment thread cosmos/dbt/selector.py Outdated
Comment thread cosmos/dbt/selector.py Outdated
Comment thread tests/dbt/test_selector.py Outdated
@YourRoyalLinus
Copy link
Copy Markdown
Contributor Author

I also noticed a bug that prevents the cache from invalidating when a DAG initially swaps LoadModes from DBT_LS to `DBT_MANIFEST or vice versa. The fix is extremely small (8 simple loc + 2 new unit tests).

Would you prefer a separate issue and PR for tracking or is there a threshold that's small enough to lump those changes into this PR? My preference is to separate them, for many reasons, but I don't want to pile on new issues and PRs unnecessarily.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.93%. Comparing base (b48b9f5) to head (9f41ab1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2316      +/-   ##
==========================================
+ Coverage   95.74%   97.93%   +2.19%     
==========================================
  Files         102      102              
  Lines        6885     6926      +41     
==========================================
+ Hits         6592     6783     +191     
+ Misses        293      143     -150     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tatiana tatiana changed the title 2312 isolate yaml selector parse errors Support error handling when using invalid YAML with LoadMode.DBT_MANIFEST and RenderConfig.selector Feb 5, 2026
@tatiana tatiana changed the title Support error handling when using invalid YAML with LoadMode.DBT_MANIFEST and RenderConfig.selector Error handle invalid YAML with LoadMode.DBT_MANIFEST and RenderConfig.selector Feb 5, 2026
Comment thread cosmos/dbt/selector.py
@tatiana
Copy link
Copy Markdown
Collaborator

tatiana commented Feb 5, 2026

Hi @YourRoyalLinus — thanks so much for following up and further improving the solution! The implementation itself, along with the documentation and tests, is very thorough.

I also noticed a bug that prevents the cache from invalidating when a DAG initially swaps LoadModes from DBT_LS to `DBT_MANIFEST or vice versa. The fix is extremely small (8 simple loc + 2 new unit tests).

Would you prefer a separate issue and PR for tracking, or is there a threshold that's small enough to lump those changes into this PR? My preference is to separate them, for many reasons, but I don't want to pile on new issues and PRs unnecessarily.

A separate PR for this fix would be great.

If you could address the minor comment I left and rebase this PR, I'm happy to approve it once the checks pass. We can release this as part of the next Cosmos release, likely 1.13.1 or 1.14.0.

Copy link
Copy Markdown
Collaborator

@tatiana tatiana left a comment

Choose a reason for hiding this comment

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

Looks great, @YourRoyalLinus , thank you!

Copilot AI review requested due to automatic review settings February 17, 2026 17:03
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

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


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

Comment thread cosmos/dbt/selector.py
Comment thread tests/dbt/test_selector.py
@tatiana
Copy link
Copy Markdown
Collaborator

tatiana commented Feb 17, 2026

I'm merging since the check that failed is unrelated to the changes in this PR, thanks a lot, @YourRoyalLinus !

@tatiana tatiana merged commit 81b1310 into astronomer:main Feb 17, 2026
77 of 79 checks passed
@tatiana tatiana added this to the Cosmos 1.13.1 milestone Feb 20, 2026
tatiana pushed a commit that referenced this pull request Feb 20, 2026
…fig.selector` (#2316)

Ensure that DAG parsing only fails for DAGs that are attempting to
render using a misconfigured yaml selector.

This was done by collecting any errors during yaml selector parsing and
raising an exception when the selector is accessed rather than when the
issue is encountered.

The exception to this is for invalid yaml structures. In those cases, we
can't be certain whether we have a valid selector name or definition.
When the graph attempts to grab the parsed selector, it would always get
a selector not found exception, hiding the error messages related to the
invalid structure.

As a result, if there is an invalid yaml structure, all DAGs using
`LoadMode.DBT_MANIFEST` and `RenderConfig.selector` will fail during dag
parse. As long as a user never directly modifies the `manifest.json`,
this should not occur.

When doing local QA, I created separate example DAGs, however keeping
them did not seem valuable as the unit tests cover the expected
behavior.

Follow up from #2257
Closes #2312

(cherry picked from commit 81b1310)
@tatiana tatiana mentioned this pull request Feb 20, 2026
tatiana added a commit that referenced this pull request Feb 25, 2026
**Enhancements**

* Change Snowflake profile mappings to default to four threads by
@tatiana in #2374
* Refactor to avoid potential future ``UnboundLocalError`` for
``producer_task`` in ``calculate_tasks_map`` by @rin in #2309

**Bug Fixes**

* Fix graph selector when using + selector with ``dbt-loom`` by
@award1230 in #2389
* Populate ``compiled_sql`` for ``InvocationMode.SUBPROCESS`` in
``ExecutionMode.WATCHER`` by @pankajkoti in #2319
* Preserve ``extra_context`` for watcher consumer task instances by
@pankajkoti in #2381
* Fix watcher: respect ``deferrable=False`` from ``operator_args`` on
consumer sensor by @pankajkoti in #2384
* Error handle invalid YAML with ``LoadMode.DBT_MANIFEST`` and
``RenderConfig.selector`` by @jonbillings in #2316
* Fix selecting model when it has the same name as folder by
@pankajastro in #2328
* Handle Param Validation errors by @tatiana in #2358
* Fix cache swap issue by @jonbillings in #2332
* Fix leaked semaphore warnings in Airflow 3 by resetting dbt adapters
by @pankajkoti in #2335

**Docs**

* Document ``ExecutionMode.KUBERNETES`` limitations by @tatiana in #2326

**Others**

* Add .airflow-registry.yaml for Airflow Provider Registry by @kaxil in
#2387
* Improve test coverage for PR #2307 by @tatiana in #2308
* Address feedback from code review #2389 by @evanvolgas in #2394

Closes:
astronomer/oss-integrations-private#333
@tatiana tatiana mentioned this pull request Feb 25, 2026
tatiana added a commit that referenced this pull request Feb 25, 2026
Enhancements

* Change Snowflake profile mappings to default to four threads by
@tatiana in #2374
* Refactor to avoid potential future ``UnboundLocalError`` for
``producer_task`` in ``calculate_tasks_map`` by @rin in #2309

Bug Fixes

* Fix graph selector when using + selector with ``dbt-loom`` by
@award1230 in #2389
* Populate ``compiled_sql`` for ``InvocationMode.SUBPROCESS`` in
``ExecutionMode.WATCHER`` by @pankajkoti in #2319
* Preserve ``extra_context`` for watcher consumer task instances by
@pankajkoti in #2381
* Fix watcher: respect ``deferrable=False`` from ``operator_args`` on
consumer sensor by @pankajkoti in #2384
* Error handle invalid YAML with ``LoadMode.DBT_MANIFEST`` and
``RenderConfig.selector`` by @YourRoyalLinus in #2316
* Fix selecting model when it has the same name as folder by
@pankajastro in #2328
* Handle Param Validation errors by @tatiana in #2358
* Fix cache swap issue by @YourRoyalLinus in #2332
* Fix leaked semaphore warnings in Airflow 3 by resetting dbt adapters
by @pankajkoti in #2335

Docs

* Document ``ExecutionMode.KUBERNETES`` limitations by @tatiana in #2326

Others

* Add .airflow-registry.yaml for Airflow Provider Registry by @kaxil in
#2387
* Improve test coverage for PR #2307 by @tatiana in #2308
* Address feedback from code review #2389 by @evanvolgas in #2394

Additional details on this change:
- The actual release was done from branch 1.13:
https://github.com/astronomer/astronomer-cosmos/releases/tag/astronomer-cosmos-v1.13.1
- This PR aims to update our CHANGELOG, and allow us to give credit to
the username that was being questioned by codespell
@pankajastro pankajastro mentioned this pull request Mar 16, 2026
pankajastro added a commit that referenced this pull request Apr 7, 2026
1.14.0 (2026-04-07)
---------------------

Breaking Changes

* Drop support for Airflow versions earlier than **2.9** by
@jedcunningham in #2288
* Fix inclusion of package models and selection/exclusion behavior by
@pankajkoti in #2357
* ``ExecutionMode.WATCHER``: The per-node ``*_status`` XCom value is now
a dict (``{"status": "<status>", "outlet_uris": [...]}``) instead of a
plain string. Any custom code that reads these internal XCom keys
directly will need to be updated by @pankajkoti in #2507

Features

* Add cluster policy support for ``ExecutionMode.WATCHER`` sensor
retries by @astro-anand in #2293
* Add debug mode to track memory utilization by @tatiana in #2327
* Add FQN selection support for ``LoadMode.DBT_MANIFEST`` by
@pankajastro in #2375
* Introduce interceptors for Cosmos tasks by @tatiana in #2419
* Add config to allow disabling dag versioning by @pankajkoti in #2470
* Implement TaskGroups by models folder by @maximilianoarcieri and
@tatiana in #1566, #2469, and #2420
* feat: implement DbtTestWatcherOperator by @michal-mrazek in #2447
* Add source freshness aware execution for ``ExecutionMode.WATCHER`` by
@pankajastro and @tatiana in #2467

* Note: Like ``ExecutionMode.WATCHER``, this feature is experimental and
its interface and implementation can change in the future.
* Add Airflow 3.2 support by @pankajastro and @pankajkoti in #2472

Enhancements

* Add watcher mode support for dbt test node states by @michal-mrazek in
#2318
* Rename watcher-mode sensor retry queue and reuse it for producer tasks
by @pankajastro in #2331
* Fix leaked semaphore warnings in Airflow 3 by resetting dbt adapters
by @pankajkoti in #2335
* Improve dbt Fusion support and related tests by @tatiana in #2356
* Default Snowflake profile mappings to four threads by @tatiana in
#2374
* Attempt to remove Pydantic as a dependency by @tatiana in #2377
* Log dbt-core and adapter versions in watcher consumer tasks by
@pankajastro in #2412
* Log model errors in watcher consumer on dbt node failure by
@pankajastro in #2431
* Reduce XCom read/write for tracking node state and errors in
ConsumerWatcher task by @pankajastro in #2471
* Remove duplicate debug log in watcher subprocess path by @tatiana in
#2494
* Simplify and unify WATCHER implementation regardless of InvocationMode
by @tatiana in #2498
* Switch to lazy imports in cosmos/__init__.py by @pankajkoti in #2531

Bug Fixes

* Handle invalid YAML errors with ``LoadMode.DBT_MANIFEST`` and
``RenderConfig.selector`` by @YourRoyalLinus in #2316
* Populate ``compiled_sql`` for ``InvocationMode.SUBPROCESS`` in
``ExecutionMode.WATCHER`` by @pankajkoti in #2319
* Fix select/exclude type mismatch by @tatiana in #2364
* Set ``emit_datasets=False`` for ``DbtTest*`` operators by @pankajastro
in #2365
* Set correct queue priority for watcher producer tasks by @pankajastro
in #2372
* Preserve ``extra_context`` for watcher consumer task instances by
@pankajkoti in #2381
* Respect ``deferrable=False`` from ``operator_args`` on watcher
consumer sensors by @pankajkoti in #2384
* Fix watcher queue precedence and add documentation by @pankajastro in
#2391
* Do not set ``compiled_sql`` on ``ExecutionMode.WATCHER`` producers by
@pankajkoti in #2440
* Remove const attribute for ``__cosmos_telemetry_metadata__`` dag param
by @pankajkoti in #2466
* Remove timeout override from Cosmos watcher sensors by @tatiana and
@claude in #2478
* Remove forced ``retries=0`` from watcher producer operators by
@tatiana in #2479
* RFC: Add patch for newer versions of amazon provider when running dbt
on EKS by @aoelvp94 in #2481
* Fix ``cosmos_debug_max_memory_mb`` XCom not pushed in Watcher sensor
tasks by @tatiana in #2503
* Fix ``TestBehavior.NONE`` and ``TestBehavior.AFTER_ALL`` exclude
ignored with selectors in ``ExecutionMode.WATCHER`` by @pankajkoti in
#2511
* Move dataset emission for ``ExecutionMode.WATCHER`` from producer to
consumer sensors by @pankajkoti in #2507

Docs

* Document cluster policy configuration for ``ExecutionMode.WATCHER``
sensor tasks by @pankajastro in #2315
* Remove outdated docs for the dbt docs plugin with Airflow 3 by
@pankajastro in #2353
* Make Watcher DBT Execution Queue heading clickable by @pankajastro in
#2354
* Update ``ExecutionMode.WATCHER`` documentation regarding test node
implementation by @jroachgolf84 in #2355
* Fix ``pre_dbt_fusion`` configuration rendering by @pankajastro in
#2369
* Add documentation for including/excluding nodes based on FQN by
@pankajastro in #2371
* Update watcher execution mode documentation by @tatiana in #2380
* Add documentation for ``DbtSeedLocalOperator`` by @jroachgolf84 in
#2383
* Fix miscellaneous Sphinx warnings by @pankajastro in #2395
* Improve contributing documentation by @lzdanski in #2397
* Add **Get Started in 5 Minutes** guide by @lzdanski in #2398
* Add Sphinx redirects package for documentation redirects by @lzdanski
in #2407
* Restructure **Getting Started** and **Guides** sections by @lzdanski
in #2418
* Add open-source quickstart by @lzdanski in #2439
* Fix documentation redirects by @lzdanski in #2442
* Restructure and refactor reference documentation by @lzdanski in #2443
* Add execution modes decision documentation by @lzdanski in #2444
* Add **Core Concepts** page to Getting Started by @lzdanski in #2448
* Add guide: *How Cosmos Works* by @lzdanski in #2449
* Update **Getting Started** overview and index pages by @lzdanski in
#2452
* Add guide: *How Cosmos Runs dbt* by @lzdanski in #2453
* Fix miscellaneous documentation links by @lzdanski in #2454
* Add Mermaid diagrams and execution mode diagrams by @lzdanski and
@tatiana in #2459
* Add documentation for memory optimization options by @pankajastro in
#2340
* Fix typo in watcher execution mode docs by @evanvolgas in #2485
* Fix minor documentation issues by @evanvolgas in #2489
* Add troubleshooting note for dbt debug logs in ExecutionMode.WATCHER
by @tatiana in #2491
* docs: unify RST header styles across documentation by @jigangz in
#2473
* docs: fix env var for rich logging by @vricciardulli in #2514
* docs: update dbt project path example for Airflow 3 Astro
compatibility by @yeoreums in #2512
* Document missing Cosmos Airflow config settings in cosmos-conf.rst by
@tatiana in #2515
* Split security-privacy policy doc and add dependency cooldown by
@pankajkoti in #2519
* Add performance optimization and troubleshooting docs by @pankajkoti
in #2521
* Update copyright year to 2026 by @tayloramurphy in #2527
* docs: Updating "Project Policies" to "Policies" in menu bar by
@jroachgolf84 in #2526

Others

* Fix tests after removing support for Airflow versions earlier than 2.9
by @tatiana in #2321
* Enable listener tests for Airflow 3.1 by @pankajastro in #2348
* Accept ``int`` or ``float`` for ``cosmos_debug_max_memory_mb`` in
integration tests by @pankajkoti in #2352
* Update ``CODEOWNERS`` to prioritize ``oss-integrations`` by @tatiana
in #2359
* Fix automatic reviewer assignment in GitHub by @tatiana and @phanikumv
in #2360
* Improve PyPI tagging by @tatiana in #2363
* Add integration tests for dbt Fusion and ``ExecutionMode.WATCHER`` by
@tatiana in #2373
* Fix Zizmor check by @tatiana in #2376
* Remove ``methodtools`` dependency by @tatiana in #2378
* Improve comments on #2389 by @evanvolgas in #2394
* Refactor ``load_from_dbt_manifest`` to reduce code complexity by
@pankajkoti in #2399
* Refactor ``_handle_no_precursors_or_descendants`` to reduce complexity
by @pankajkoti in #2400
* Improve issue templates by @tatiana in #2401
* Avoid running tests when only docs change by @tatiana in #2402
* Add ``no-reload`` target for serving docs locally by @pankajkoti in
#2405
* Fix test hash checks on macOS by @tatiana in #2406
* Attempt deterministic dbt project copy in test fixtures by @pankajkoti
in #2409
* Pin ``virtualenv <21`` due to hatch incompatibility in CI by
@pankajkoti in #2410
* Revert virtualenv pin for hatch installation in CI by @pankajkoti in
#2426
* Add version comments for commit SHA pinned GitHub Actions by
@pankajkoti in #2436
* Fix ``hatch run docs:build`` issues by @tatiana in #2437
* Minor code improvements by @dnskr in #2446
* Pre-commit autoupdate by @pre-commit-ci in #2367, #2396, #2422, #2451,
#2468, #2495, and #2516
* Add file to support Claude understanding the Cosmos repository by
@tatiana in #2458
* Dependency updates by @dependabot in #2368, #2425, #2435, #2465,
#2475, #2504, #2518, and #2528
* Isolate Scarf telemetry integration test into its own CI job by
@pankajkoti and @claude in #2477
* ci: upgrade Airflow version to 3.1 in MyPy type-check job by @yeoreums
in #2506
* Add commit message guidelines to CLAUDE.md by @pankajkoti in #2509
* Extend skipping tests in CI for more non-code file changes by
@pankajkoti in #2510
* Add Dependabot pre-commit support with 7-day cooldown by @pankajkoti
in #2517
* Enforce zero warnings policy for documentation by @dnskr in #2513

Co-authored-by: Pankaj Koti <pankajkoti699@gmail.com>
Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Pankaj Koti <pankajkoti699@gmail.com>
Co-authored-by: Tatiana Al-Chueyr <tatiana.alchueyr@gmail.com>
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.

[Feature] Isolate YamlSelector parse errors

3 participants