-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send context using in venv operator #41039
Conversation
The warning |
|
The warning seems to be occurring in a place that seems unrelated to the area I modified. I'm not sure where to look, so can you give me a little hint? self = <airflow.utils.decorators._autostacklevel_warn object at 0xf74179d49cd0>
message = '`soft_fail` is deprecated and will be removed in a future version. Please provide skip_policy=SkipPolicy.skip_on_soft_error instead.'
category = <class 'airflow.exceptions.RemovedInAirflow3Warning'>, stacklevel = 3
source = None
def warn(self, message, category=None, stacklevel=1, source=None):
> self.warnings.warn(message, category, stacklevel + 2, source)
E airflow.exceptions.RemovedInAirflow3Warning: `soft_fail` is deprecated and will be removed in a future version. Please provide skip_policy=SkipPolicy.skip_on_soft_error instead.
airflow/utils/decorators.py:114: RemovedInAirflow3Warning
_________ TestSFTPSensor.test_sftp_failure[True-AirflowSkipException] __________
self = <tests.providers.sftp.sensors.test_sftp.TestSFTPSensor object at 0xf7414ac87100>
sftp_hook_mock = <MagicMock name='SFTPHook' id='271858442834320'>
soft_fail = True
expected_exception = <class 'airflow.exceptions.AirflowSkipException'>
@pytest.mark.parametrize(
"soft_fail, expected_exception", ((False, OSError), (True, AirflowSkipException))
)
@patch("airflow.providers.sftp.sensors.sftp.SFTPHook")
def test_sftp_failure(self, sftp_hook_mock, soft_fail: bool, expected_exception):
sftp_hook_mock.return_value.get_mod_time.side_effect = OSError(SFTP_FAILURE, "SFTP failure")
> sftp_sensor = SFTPSensor(
task_id="unit_test", path="/path/to/file/1970-01-01.txt", soft_fail=soft_fail
)
tests/providers/sftp/sensors/test_sftp.py:61: |
69a826c
to
c4e4be9
Compare
sample dag script: 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: *** 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 PR looks good to me, at least for Airflow 2. While the down side is it creates another version of serialized context in a sort of manual way and outside of serializer. I think ideally in Airflow 3, it can utilize serde to serialize to entire context, and then translate it to a more human readable json in this case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall - had some minor comments in the code plus a couple of questions:
- Did you check that it works for both
PythonVirtualenvOperator
andExternalPythonOperator
? (both inherit from_BasePythonVirtualenvOperator
) - Is there a way to test both operators above with this feature as part of the tests in
tests/operators/test_python.py
?
Also ,it would be great to add a newsfragment, so other people would be aware of this feature.
c4e4be9
to
68f0e34
Compare
I moved test code from |
68f0e34
to
570f7b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing!
To wrap it up, could you please add a newsfragment? (feature type)
9a8a805
to
1f32e33
Compare
Added a newsfragment. |
67794d3
to
9969aaf
Compare
One question, why can we not always provide the context when possible? Does this have a negative effect when the context is not needed? |
I used |
I think it's a bit safer approach this way. It could be, for example that we miss some context serialization "glitch" that will make serialization to crash. Or maybe a future version of Airflow will add a bug there, or maybe someones python code already created "MockPython" object and the script will fail to parse (not very likely but I've seen stranger things in Airflow's vast user base). Python operators are used for various things and I think any change in their scripts should be made in a very "safe" way. |
9969aaf
to
7c31954
Compare
5752e4a
to
4501304
Compare
Co-authored-by: Elad Kalif <[email protected]>
This reverts commit 9efc8ed343556526714010670f30f70c464ec892.
09f0de2
to
418070f
Compare
This reverts commit da55393.
related: #34158
allow
airflow.operators.python.get_current_context()
in venvlimits:
airflow
in venvsample dag script:
output:
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.