ferruzzi commented on PR #75363:
URL: https://github.com/apache/airflow/pull/75363#issuecomment-7016788489
My agent called this out and it needs testing/verification. We're
essentially making `deadline` a reserved keyword here, and any `@task()` which
is currently using that as a parameter name is going to start raising an
exception on import.
Here is Claude's proiposed fix, you'd need to test it:
```
1. task-sdk/src/airflow/sdk/definitions/context.py:124: exclude deadline
the same way loop is excluded.
# ``loop`` exists only in loop task groups and ``deadline`` only in
deadline callbacks, so tasks may use either name.
KNOWN_CONTEXT_KEYS: set[str] = set(Context.__annotations__.keys()) -
{"loop", "deadline"}
The deadline entry stays in the Context TypedDict, so type checkers still
know callbacks can read context["deadline"]. The callback path never reads
KNOWN_CONTEXT_KEYS. Its only users are the decorator, task handlers,
@task.stub and the YAML importer, which are the five places that would stop
rejecting the name.
2. task-sdk/tests/task_sdk/execution_time/test_context.py:3270: this test
currently requires deadline to be reserved. Change it to check against the
TypedDict, and add the regression check:
def test_keys_are_context_keys(self):
from airflow.sdk import DAG
from airflow.sdk.definitions.context import KNOWN_CONTEXT_KEYS,
Context
context = build_deadline_callback_context(
_dag_run(), DAG("ctx_dag"), deadline_id="abc",
deadline_time="2024-06-15T13:00:00+00:00"
)
assert set(context) <= set(Context.__annotations__)
# Only deadline callbacks get it, so a task parameter may still be
called ``deadline``.
assert "deadline" not in KNOWN_CONTEXT_KEYS
3. airflow-core/newsfragments/75363.significant.rst:9-10: delete the
sentence "deadline is now a context key, so, like ds or params, a @task
argument with that name can only default to None." With the fix it would no
longer be true.
```
--
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]