phi-friday commented on PR #41039: URL: https://github.com/apache/airflow/pull/41039#issuecomment-2252948381
sample dag script: ```python from __future__ import annotations from pendulum import datetime from airflow.decorators import dag, task @dag(start_date=datetime(2022, 1, 1), schedule=None, catchup=False) def context_sample(): @task.virtualenv(use_airflow_context=True) def print_context() -> None: from pprint import pprint from airflow.operators.python import get_current_context context = get_current_context() pprint(context) print_context() context_sample() ``` output: ```shell *** Found local files: *** * /root/airflow/logs/dag_id=context_sample/run_id=manual__2024-07-26T14:57:31.727299+00:00/task_id=print_context/attempt=1.log [2024-07-26, 14:57:32 UTC] {local_task_job_runner.py:123} ▼ Pre task execution logs [2024-07-26, 14:57:32 UTC] {taskinstance.py:2559} INFO - Dependencies all met for dep_context=non-requeueable deps ti=<TaskInstance: context_sample.print_context manual__2024-07-26T14:57:31.727299+00:00 [queued]> [2024-07-26, 14:57:32 UTC] {taskinstance.py:2559} INFO - Dependencies all met for dep_context=requeueable deps ti=<TaskInstance: context_sample.print_context manual__2024-07-26T14:57:31.727299+00:00 [queued]> [2024-07-26, 14:57:32 UTC] {taskinstance.py:2812} INFO - Starting attempt 1 of 1 [2024-07-26, 14:57:33 UTC] {taskinstance.py:2835} INFO - Executing <Task(_PythonVirtualenvDecoratedOperator): print_context> on 2024-07-26 14:57:31.727299+00:00 [2024-07-26, 14:57:33 UTC] {standard_task_runner.py:72} INFO - Started process 307 to run task [2024-07-26, 14:57:33 UTC] {standard_task_runner.py:104} INFO - Running: ['***', 'tasks', 'run', 'context_sample', 'print_context', 'manual__2024-07-26T14:57:31.727299+00:00', '--job-id', '3', '--raw', '--subdir', 'DAGS_FOLDER/context_sample.py', '--cfg-path', '/tmp/tmp8levtm38'] [2024-07-26, 14:57:33 UTC] {standard_task_runner.py:105} INFO - Job 3: Subtask print_context [2024-07-26, 14:57:33 UTC] {task_command.py:467} INFO - Running <TaskInstance: context_sample.print_context manual__2024-07-26T14:57:31.727299+00:00 [running]> on host 2393e38fe647 [2024-07-26, 14:57:33 UTC] {taskinstance.py:3079} INFO - Exporting env vars: AIRFLOW_CTX_DAG_OWNER='***' AIRFLOW_CTX_DAG_ID='context_sample' AIRFLOW_CTX_TASK_ID='print_context' AIRFLOW_CTX_EXECUTION_DATE='2024-07-26T14:57:31.727299+00:00' AIRFLOW_CTX_TRY_NUMBER='1' AIRFLOW_CTX_DAG_RUN_ID='manual__2024-07-26T14:57:31.727299+00:00' [2024-07-26, 14:57:33 UTC] {taskinstance.py:732} ▲▲▲ Log group end [2024-07-26, 14:57:33 UTC] {process_utils.py:183} INFO - Executing cmd: /usr/local/bin/python -m virtualenv /tmp/venvbvs9imwj --system-site-packages --python=python [2024-07-26, 14:57:33 UTC] {process_utils.py:187} INFO - Output: [2024-07-26, 14:57:33 UTC] {process_utils.py:191} INFO - created virtual environment CPython3.9.19.final.0-64 in 306ms [2024-07-26, 14:57:33 UTC] {process_utils.py:191} INFO - creator CPython3Posix(dest=/tmp/venvbvs9imwj, clear=False, no_vcs_ignore=False, global=True) [2024-07-26, 14:57:33 UTC] {process_utils.py:191} INFO - seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv) [2024-07-26, 14:57:33 UTC] {process_utils.py:191} INFO - added seed packages: pip==24.1, setuptools==70.1.0, wheel==0.43.0 [2024-07-26, 14:57:33 UTC] {process_utils.py:191} INFO - activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator [2024-07-26, 14:57:33 UTC] {process_utils.py:183} INFO - Executing cmd: /tmp/venvbvs9imwj/bin/pip install -r /tmp/venvbvs9imwj/requirements.txt [2024-07-26, 14:57:33 UTC] {process_utils.py:187} INFO - Output: [2024-07-26, 14:57:37 UTC] {process_utils.py:191} INFO - [2024-07-26, 14:57:37 UTC] {process_utils.py:191} INFO - [notice] A new release of pip is available: 24.1 -> 24.1.2 [2024-07-26, 14:57:37 UTC] {process_utils.py:191} INFO - [notice] To update, run: python -m pip install --upgrade pip [2024-07-26, 14:57:37 UTC] {process_utils.py:183} INFO - Executing cmd: /tmp/venvbvs9imwj/bin/python /tmp/venv-callq63jm1tl/script.py /tmp/venv-callq63jm1tl/script.in /tmp/venv-callq63jm1tl/script.out /tmp/venv-callq63jm1tl/string_args.txt /tmp/venv-callq63jm1tl/termination.log /tmp/venv-callq63jm1tl/***_context.json [2024-07-26, 14:57:37 UTC] {process_utils.py:187} INFO - Output: [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - {'dag': {'_dag_id': 'context_sample', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_default_view': 'grid', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_processor_dags_folder': '/files/dags', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_task_group': {'_group_id': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'children': {'print_context': ['operator', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'print_context']}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'downstream_group_ids': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'downstream_task_ids': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'prefix_group_id': True, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'tooltip': '', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ui_color': 'CornflowerBlue', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ui_fgcolor': '#000', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'upstream_group_ids': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'upstream_task_ids': []}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'catchup': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'dag_dependencies': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'edge_info': {}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'fileloc': '/files/dags/context_sample.py', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'params': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'schedule_interval': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_date': 1640995200.0, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'tasks': [{'__type': 'operator', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '__var': {'_is_empty': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_log_config_logger_name': '***.task.operators', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_needs_expansion': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_operator_name': '@task.virtualenv', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_task_module': '***.decorators.python_virtualenv', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_task_type': '_PythonVirtualenvDecoratedOperator', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'downstream_task_ids': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'is_setup': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'is_teardown': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'on_failure_fail_dagrun': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_args': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_kwargs': {}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'pool': 'default_pool', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'requirements': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_from_trigger': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_trigger_args': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'task_id': 'print_context', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'template_ext': ['.txt'], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'template_fields': ['venv_cache_path', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_args', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'index_urls', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'requirements', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'templates_dict', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_kwargs'], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'template_fields_renderers': {'op_args': 'py', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_kwargs': 'py', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'templates_dict': 'json'}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ui_color': '#ffefeb', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ui_fgcolor': '#000', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'weight_rule': 'downstream'}}], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'timezone': 'UTC'}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'dag_run': {'clear_number': 0, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'conf': {}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'creating_job_id': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'dag_hash': '331c7d69cf865719c0509d0b3d4e44f0', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'dag_id': 'context_sample', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'data_interval_end': '2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'data_interval_start': '2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'end_date': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'execution_date': '2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'external_trigger': True, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'id': 1, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'last_scheduling_decision': '2024-07-26T14:57:32.851392+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'log_template_id': 2, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'queued_at': '2024-07-26T14:57:31.749764+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'run_id': 'manual__2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'run_type': 'manual', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_date': '2024-07-26T14:57:32.796911+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'state': 'running', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'updated_at': '2024-07-26T14:57:32.853627+00:00'}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'data_interval_end': '2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'data_interval_start': '2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ds': '2024-07-26', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ds_nodash': '20240726', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'expanded_ti_count': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'logical_date': '2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'map_index_template': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'params': {}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'prev_data_interval_end_success': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'prev_data_interval_start_success': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'prev_end_date_success': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'prev_start_date_success': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'run_id': 'manual__2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'task': {'_is_empty': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_log_config_logger_name': '***.task.operators', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_needs_expansion': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_operator_name': '@task.virtualenv', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_task_module': '***.decorators.python_virtualenv', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - '_task_type': '_PythonVirtualenvDecoratedOperator', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'downstream_task_ids': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'is_setup': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'is_teardown': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'on_failure_fail_dagrun': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_args': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_kwargs': {}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'pool': 'default_pool', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'requirements': [], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_from_trigger': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_trigger_args': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'task_id': 'print_context', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'template_ext': ['.txt'], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'template_fields': ['venv_cache_path', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_args', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'index_urls', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'requirements', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'templates_dict', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_kwargs'], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'template_fields_renderers': {'op_args': 'py', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'op_kwargs': 'py', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'templates_dict': 'json'}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ui_color': '#ffefeb', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ui_fgcolor': '#000', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'weight_rule': 'downstream'}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'task_instance': {'dag_id': 'context_sample', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'end_date': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'executor': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'executor_config': {}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'key': ['context_sample', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'print_context', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'manual__2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 1, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - -1], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'map_index': -1, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'pool': 'default_pool', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'priority_weight': 1, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'queue': 'default', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'run_as_user': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'run_id': 'manual__2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_date': '2024-07-26T14:57:32.992994+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'state': 'running', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'task_id': 'print_context', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'try_number': 1}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'task_instance_key_str': 'context_sample__print_context__20240726', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'test_mode': False, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ti': {'dag_id': 'context_sample', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'end_date': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'executor': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'executor_config': {}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'key': ['context_sample', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'print_context', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'manual__2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 1, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - -1], [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'map_index': -1, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'pool': 'default_pool', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'priority_weight': 1, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'queue': 'default', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'run_as_user': None, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'run_id': 'manual__2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'start_date': '2024-07-26T14:57:32.992994+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'state': 'running', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'task_id': 'print_context', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'try_number': 1}, [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ts': '2024-07-26T14:57:31.727299+00:00', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ts_nodash': '20240726T145731', [2024-07-26, 14:57:41 UTC] {process_utils.py:191} INFO - 'ts_nodash_with_tz': '20240726T145731.727299+0000'} [2024-07-26, 14:57:41 UTC] {python.py:240} INFO - Done. Returned value was: None [2024-07-26, 14:57:41 UTC] {taskinstance.py:341} ▼ Post task execution logs [2024-07-26, 14:57:41 UTC] {taskinstance.py:353} INFO - Marking task as SUCCESS. dag_id=context_sample, task_id=print_context, run_id=manual__2024-07-26T14:57:31.727299+00:00, execution_date=20240726T145731, start_date=20240726T145732, end_date=20240726T145741 [2024-07-26, 14:57:41 UTC] {local_task_job_runner.py:261} INFO - Task exited with return code 0 [2024-07-26, 14:57:41 UTC] {taskinstance.py:3847} INFO - 0 downstream tasks scheduled from follow-on schedule check [2024-07-26, 14:57:41 UTC] {local_task_job_runner.py:240} ▲▲▲ Log group end ``` -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org