Copilot commented on code in PR #70990:
URL: https://github.com/apache/airflow/pull/70990#discussion_r3704254459
##########
airflow-core/src/airflow/dag_processing/processor.py:
##########
@@ -336,16 +336,22 @@ def _execute_callbacks(
)
else:
log.debug("Processing Callback Request", request=request.to_json())
- with BundleVersionLock(
- bundle_name=request.bundle_name,
- bundle_version=request.bundle_version,
- ):
- if isinstance(request, TaskCallbackRequest):
- _execute_task_callbacks(dagbag, request, log)
- elif isinstance(request, DagCallbackRequest):
- _execute_dag_callbacks(dagbag, request, log)
- elif isinstance(request, EmailRequest):
- _execute_email_callbacks(dagbag, request, log)
+ # A failed request (e.g. the Dag or task was removed since the callback
+ # was scheduled) must not abort the remaining requests in this batch --
+ # they were already popped from the manager's queue and would be lost.
+ try:
Review Comment:
`request.to_json()` is called before the per-request `try:` and then called
again in the `except` block. If serialization ever raises (e.g.
unexpected/unserializable fields), the batch can still abort and the original
exception may be masked. It also does duplicate work. Consider serializing once
with a safe fallback and reusing that value for both debug and exception
logging.
##########
airflow-core/src/airflow/dag_processing/processor.py:
##########
@@ -361,7 +367,9 @@ def _execute_dag_callbacks(dagbag: DagBag, request:
DagCallbackRequest, log: Fil
ctx_from_server = request.context_from_server
if ctx_from_server is not None and ctx_from_server.last_ti is not None:
- task = dag.get_task(ctx_from_server.last_ti.task_id)
+ _, task = _get_dag_with_task(dagbag, request.dag_id,
ctx_from_server.last_ti.task_id)
+ if TYPE_CHECKING:
+ assert task is not None
Review Comment:
Avoid adding new `assert` statements in non-test code (even under
`TYPE_CHECKING`). Here it’s only used for type narrowing, and `assert` is easy
to miss in reviews and is broadly discouraged in Airflow core. Prefer an
explicit runtime guard (which also narrows types for type checkers) to keep the
behavior and style consistent.
--
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]