Skip to content

RuntimeTaskInstance context does not contain log_url #50330

@jnstockley

Description

@jnstockley

Apache Airflow version

3.0.0

If "Other Airflow 2 version" selected, which one?

No response

What happened?

The Task Context does not contain the log_url parameter, this causes SmtpNotifier to fail to send email when using on_failure_callback, on_success_callback, etc. SmtpNotifier fails since in the jinja2 email template it requires ti.log_url

What you think should happen instead?

Tek Task context should include log_url or the jinja2 should be updated by removing log_url or using a different way to include log_url

How to reproduce

Create a task as follows

@task()
    def send_email(**context):
        ti: RuntimeTaskInstance = context['ti']

        smtp = SmtpNotifier(to=to_email, smtp_conn_id="SMTP", from_email=from_email')
        smtp.notify(context)

Check error logs stating

[2025-05-08, 01:28:34] ERROR - Task failed with exception: source="task"
UndefinedError: 'airflow.sdk.execution_time.task_runner.RuntimeTaskInstance object' has no attribute 'log_url'
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 838 in run
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1130 in _execute_task
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 408 in wrapper
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/decorator.py", line 251 in execute
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 408 in wrapper
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py", line 212 in execute
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/python.py", line 235 in execute_callable
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/callback_runner.py", line 81 in run
File "/opt/airflow/dags/Airflow_Cleanup.py", line 98 in send_email
File "/opt/airflow/plugins/notifier/SMTP.py", line 149 in notify
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/templater.py", line 121 in _do_render_template_fields
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/templater.py", line 177 in render_template
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/notifier.py", line 57 in _render
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/definitions/_internal/templater.py", line 133 in _render
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/helpers.py", line 244 in render_template_to_string
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/helpers.py", line 239 in render_template
File "<template>", line 37 in root
File "/home/airflow/.local/lib/python3.12/site-packages/jinja2/runtime.py", line 859 in _fail_with_undefined_error

Operating System

Linux

Versions of Apache Airflow Providers

apache-airflow-providers-common-compat==1.6.1

Deployment

Other Docker-based deployment

Deployment details

Custom Docker image using official Docker images as base, https://github.com/jnstockley/airflow/blob/main/Dockerfile

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Labels

area:corekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions