Skip to content

fix(amazon): chain deferral in EmrServerlessDeleteApplicationOperator so DeleteApplication is actually called - #72124

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix-emr-serverless-delete-deferrable-72123
Open

fix(amazon): chain deferral in EmrServerlessDeleteApplicationOperator so DeleteApplication is actually called#72124
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix-emr-serverless-delete-deferrable-72123

Conversation

@waterWang

Copy link
Copy Markdown

Closes: #72123

Problem

When deferrable=True, EmrServerlessDeleteApplicationOperator never calls the DeleteApplication API. The task succeeds and logs EMR serverless application <id> deleted successfully, but the application is only stopped, never deleted.

Root cause

EmrServerlessDeleteApplicationOperator subclasses EmrServerlessStopApplicationOperator. In deferrable mode the parent's execute() defers with a hardcoded method_name="execute_complete", which raises TaskDeferred before the subclass's execute() can reach the delete_application() call. On resume, the subclass's execute_complete() handler runs — but that handler only validates the stop trigger's event and logs success, so DeleteApplication is never issued.

Fix

Follow the chained-deferral pattern the stop operator already uses for the force_stop path (executestop_applicationexecute_complete):

  1. Add a class attribute stop_complete_method_name: str = "execute_complete" to EmrServerlessStopApplicationOperator, used in place of both hardcoded method_name="execute_complete" occurrences.
  2. EmrServerlessDeleteApplicationOperator sets stop_complete_method_name = "stop_complete" and implements stop_complete() to issue DeleteApplication and defer on EmrServerlessDeleteApplicationTrigger, leaving execute_complete to handle only the delete trigger's event.

Backwards compatible: execute_complete still exists for tasks already deferred by an older version at upgrade time.

Verification

  • New unit test test_delete_application_deferrable_deletes_after_stop proves the full chained flow: first defer is on the StopApplicationTrigger resuming at stop_complete, which calls delete_application and defers on the DeleteApplicationTrigger resuming at execute_complete.

… to actually call DeleteApplication (apache#72123)

When `deferrable=True`, `EmrServerlessDeleteApplicationOperator.execute()`
never reaches the `delete_application` call because the parent operator
`EmrServerlessStopApplicationOperator` defers with a hardcoded
`method_name="execute_complete"`, which raises `TaskDeferred` before the
subclass can issue the delete. On resume the subclass's `execute_complete`
handler runs, but only validates the stop event and logs success — the
application is never deleted.

Fix:
- Add a class attribute `stop_complete_method_name` to the stop operator
  so subclasses can override where to resume after the application stops.
- `EmrServerlessDeleteApplicationOperator` sets
  `stop_complete_method_name = "stop_complete"` and implements
  `stop_complete()` to issue `DeleteApplication` and defer on the
  `EmrServerlessDeleteApplicationTrigger`, leaving `execute_complete`
  to handle only the delete trigger's event.

This is the same chained-deferral pattern already used by the stop
operator for the `force_stop` path (`execute` → `stop_application` →
`execute_complete`).

Signed-off-by: waterWang <waterWang@users.noreply.github.com>
@waterWang
waterWang requested a review from o-nikolas as a code owner August 27, 2026 00:08
@boring-cyborg boring-cyborg Bot added area:providers provider:amazon AWS/Amazon - related issues labels Aug 27, 2026

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title should follow the same suggestion in #71880

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:amazon AWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EmrServerlessDeleteApplicationOperator never calls DeleteApplication when deferrable=True (silently leaks applications, task reports success)

2 participants