amoghrajesh commented on code in PR #73030:
URL: https://github.com/apache/airflow/pull/73030#discussion_r4093287414
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/task_instances.py:
##########
@@ -89,6 +89,7 @@ class TaskInstanceResponse(BaseModel):
queued_by_job: JobResponse | None = Field(alias="triggerer_job")
dag_version: DagVersionResponse | None
team_name: str | None = None
+ state_reason: str | None = Field(default=None,
validation_alias="retry_reason")
Review Comment:
Added the validator on both models, matching connections.py. Tests for both,
and both fail if the validators are removed.
Two things I hit that you'll want to know.
I checked this by hand.
Used this dag:
```python
from __future__ import annotations
from datetime import datetime
from airflow.hooks.base import BaseHook
from airflow.sdk import DAG, task
from airflow.sdk.definitions.retry_policy import RetryAction, RetryDecision,
RetryPolicy
class EchoExceptionRetryPolicy(RetryPolicy):
"""Puts the raw exception text into the reason, as a hand-written policy
commonly would."""
def evaluate(self, exception, try_number, max_tries, context=None):
return RetryDecision(action=RetryAction.FAIL, reason=f"auth:
{exception}")
with DAG(
dag_id="state_reason_redaction",
start_date=datetime(2026, 1, 1),
schedule=None,
catchup=False,
tags=["manual-check"],
):
@task(retries=0, retry_policy=EchoExceptionRetryPolicy())
def leak_password_into_the_reason():
password = BaseHook.get_connection("demo_conn").password
raise RuntimeError(f"403 Forbidden: token {password} expired")
leak_password_into_the_reason()
```
This connection:
```shell
Successfully added `conn_id`=demo_conn
| conn_ty | | | |
conn_id | pe | host | login | port | extra
=========+=========+=========+=======+======+======
demo_con | http | example | None | None | {}
n | | .com | | |
```
Result
<img width="1781" height="992" alt="image"
src="https://github.com/user-attachments/assets/9d59f49c-6ee2-4d45-8b9c-7947abaa0b8a"
/>
--
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]