Skip to content

Refactor to avoid potential future UnboundLocalError for producer_task in calculate_tasks_map#2309

Merged
tatiana merged 2 commits into
astronomer:mainfrom
RinZ27:fix/producer-task-unbound-error
Feb 5, 2026
Merged

Refactor to avoid potential future UnboundLocalError for producer_task in calculate_tasks_map#2309
tatiana merged 2 commits into
astronomer:mainfrom
RinZ27:fix/producer-task-unbound-error

Conversation

@RinZ27
Copy link
Copy Markdown
Contributor

@RinZ27 RinZ27 commented Jan 30, 2026

Fixed a potential scope issue where producer_task could be accessed before initialization in the calculate_tasks_map function. While I was digging through the watcher implementation, it became clear that the variable was only defined within a specific branch but referenced later in a separate block. Initializing it at the top and simplifying the downstream check makes the code much more robust against accidental crashes.

Updating the logic to verify the presence of the task object itself instead of re-checking the execution mode keeps the flow consistent. This ensures the dependency setup only triggers when the producer is actually available.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 30, 2026

Deploy Preview for astronomer-cosmos canceled.

Name Link
🔨 Latest commit a9e75b9
🔍 Latest deploy log https://app.netlify.com/projects/astronomer-cosmos/deploys/698092697021ea0008b42e21

@RinZ27 RinZ27 force-pushed the fix/producer-task-unbound-error branch from 16e571b to 465b411 Compare January 30, 2026 13:44
@RinZ27 RinZ27 force-pushed the fix/producer-task-unbound-error branch from 465b411 to 4287f7c Compare January 30, 2026 13:50
@RinZ27 RinZ27 force-pushed the fix/producer-task-unbound-error branch from 4287f7c to 3f91e7a Compare January 30, 2026 13:53
@tatiana tatiana changed the title fix: resolve potential UnboundLocalError for producer_task in calculate_tasks_map Refactor to avoid potential future UnboundLocalError for producer_task in calculate_tasks_map Jan 30, 2026
@tatiana tatiana added this to the Cosmos 1.13.1 milestone Jan 30, 2026
@RinZ27 RinZ27 force-pushed the fix/producer-task-unbound-error branch from 3f91e7a to f1109f5 Compare January 30, 2026 14:50
@RinZ27 RinZ27 force-pushed the fix/producer-task-unbound-error branch from f1109f5 to d186a21 Compare January 31, 2026 03:27
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.12%. Comparing base (0f6efed) to head (a9e75b9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2309   +/-   ##
=======================================
  Coverage   98.12%   98.12%           
=======================================
  Files         100      100           
  Lines        6733     6733           
=======================================
  Hits         6607     6607           
  Misses        126      126           

☔ 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.

@RinZ27 RinZ27 force-pushed the fix/producer-task-unbound-error branch from d186a21 to a9e75b9 Compare February 2, 2026 12:02
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.

Thanks for improving the code, @RinZ27 ! Refactors like this improve code maintainability and help avoid issues in the future. We'll release this as part of the next Cosmos release, very likely 1.13.1.

@tatiana tatiana merged commit c2731af into astronomer:main Feb 5, 2026
90 checks passed
@RinZ27
Copy link
Copy Markdown
Contributor Author

RinZ27 commented Feb 5, 2026

Happy to contribute to the project and glad to hear it'll be in the 1.13.1 release. @tatiana

@RinZ27 RinZ27 deleted the fix/producer-task-unbound-error branch February 5, 2026 12:17
tatiana pushed a commit that referenced this pull request Feb 20, 2026
…task` in `calculate_tasks_map` (#2309)

Fixed a potential scope issue where `producer_task` could be accessed
before initialization in the `calculate_tasks_map` function. While I was
digging through the watcher implementation, it became clear that the
variable was only defined within a specific branch but referenced later
in a separate block. Initializing it at the top and simplifying the
downstream check makes the code much more robust against accidental
crashes.

Updating the logic to verify the presence of the task object itself
instead of re-checking the execution mode keeps the flow consistent.
This ensures the dependency setup only triggers when the producer is
actually available.

(cherry picked from commit c2731af)
@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
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.

2 participants