pedro-cf opened a new issue, #43354:
URL: https://github.com/apache/airflow/issues/43354

   ### Apache Airflow version
   
   2.10.2
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   When using the `@task.skip_if` decorator in combination with the 
`@task.virtualenv` decorator in an Airflow DAG using the TaskFlow API, the task 
fails with a `NameError: name 'task' is not defined` error. This occurs even 
though the task should be skipped based on the condition provided.
   
   
   ### What you think should happen instead?
   
   The task should be skipped without executing the task code or creating a 
virtual environment.
   
   
   ### How to reproduce
   
   Run the following DAG:
   
   ```python
   from datetime import datetime
   from airflow.decorators import dag, task
   from airflow.operators.python import get_current_context
   
   @dag(
       dag_id='taskflow_skip_if_virtualenv_bug',
       start_date=datetime(2023, 1, 1),
       schedule=None,
       is_paused_upon_creation=False,
       catchup=False
   )
   def taskflow_skip_if_virtualenv_bug():
   
       @task.skip_if(condition=lambda context: False)
       @task.virtualenv(
           requirements=["stomp-py==8.1.2", "requests==2.31.0"],
           venv_cache_path="/tmp",
       )
       def potentially_skipped_task():
           import requests
           print("This task should be skipped, but it might run anyway!")
           response = requests.get("https://example.com";)
           print(f"Response status code: {response.status_code}")
   
       potentially_skipped_task()
   
   taskflow_skip_if_virtualenv_bug()
   ```
   
   ### Operating System
   
   Ubuntu 22
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Docker-Compose
   
   ### Deployment details
   
   LocalExecutor
   
   ### Anything else?
   
   Error logs:
   
   ```
   [2024-10-24, 15:18:42 UTC] {process_utils.py:194} INFO - Traceback (most 
recent call last):
   [2024-10-24, 15:18:42 UTC] {process_utils.py:194} INFO -   File 
"/tmp/venv-call4tpdkgmu/script.py", line 18, in <module>
   [2024-10-24, 15:18:42 UTC] {process_utils.py:194} INFO -     
@task.skip_if(condition=lambda context: False)
   [2024-10-24, 15:18:42 UTC] {process_utils.py:194} INFO -      ^^^^
   [2024-10-24, 15:18:42 UTC] {process_utils.py:194} INFO - NameError: name 
'task' is not defined
   [2024-10-24, 15:18:43 UTC] {taskinstance.py:3310} ERROR - Task failed with 
exception
   ```
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to