Repository navigation
Fix EmrContainerSensor reporting success for an unknown job state - #72500
Merged
vincbeck merged 2 commits intoSep 4, 2026
Merged
Conversation
EmrContainerSensor.poke() returned True for any state that was neither a failure state nor an intermediate state, so an unknown state was treated as a successful job run. SUCCESS_STATES was declared but never used. EmrContainerHook.check_query_status returns None when it swallows a generic ClientError, and poll_query_status passes that None through once max_polling_attempts is reached. A throttled or otherwise transiently failing DescribeJobRun therefore marked the task successful while the job was still running. Check state against SUCCESS_STATES instead, and add tests for the None and unrecognised-state cases.
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
vincbeck
approved these changes
Sep 4, 2026
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What happened
EmrContainerSensor.poke() treats "not a failure state and not an intermediate state" as success:
python
INTERMEDIATE_STATES = ("PENDING", "SUBMITTED", "RUNNING")
FAILURE_STATES = ("FAILED", "CANCELLED", "CANCEL_PENDING")
SUCCESS_STATES = ("COMPLETED",) # declared, never used
def poke(self, context: Context) -> bool:
state = self.hook.poll_query_status(...)
if state in self.FAILURE_STATES:
raise AirflowException(...)
if state in self.INTERMEDIATE_STATES:
return False
return True # anything else is "success"
SUCCESS_STATES is defined on the class and never referenced anywhere in the file.
Why it matters
The fall-through is reachable through the hook's own documented behaviour:
EmrContainerHook.check_query_status catches a generic ClientError, logs it and returns None. Its docstring says "Returns None or one of valid query states."
EmrContainerHook.poll_query_status handles that case explicitly, logging "Try %s: Invalid query state. Retrying again", and once max_polling_attempts is reached it does return query_state, which is None.
poke() finds None in neither tuple and returns True.
So a
ThrottlingException, or any transientDescribeJobRunfailure that outlastsmax_retries, marks the Airflow task successful and releases every downstream task while the EMR on EKS job is still running. The same applies to any job-run state AWS adds that Airflow does not yet know about.Worth noting the precondition: reaching the
Nonereturn requiresmax_retriesto be set on the sensor, since that is what bounds the hook's polling loop. Left unset, the loop spins indefinitely instead of returning.The change
diff
if state in self.INTERMEDIATE_STATES:
return False
Why the existing tests did not catch this
test_emr_containers.py covers all seven documented EMR on EKS states: PENDING, SUBMITTED, RUNNING, COMPLETED, FAILED, CANCELLED, CANCEL_PENDING. Every one behaves correctly today. Nothing covered the None that the hook is documented to return, or an unrecognised state.
This PR adds test_poke_unknown_state and test_poke_unrecognised_state to close that gap.
Test results
Before the fix:
test_poke_unknown_state FAILED
test_poke_unrecognised_state FAILED
2 failed, 9 passed
with the hook logging Try 1: Invalid query state. Retrying again and Try 1: Query is still in non-terminal state - SOME_FUTURE_STATE respectively, immediately before poke() returned True.
After the fix:
11 passed
Behaviour change worth calling out
An unknown state now makes the sensor keep poking until its own timeout rather than succeed immediately. That is the minimal, fail-safe change, but the alternative would be to raise on a state that is in none of the three tuples so the failure is loud instead of a timeout. Happy to change it to whichever the maintainers prefer.
Was generative AI tooling used to co-author this PR?
Generated-by: Claude following the guidelines
Gen-AI disclosure
I used Claude to assist with this contribution. The defect was found by reviewing provider modules that carry no unit tests; the fix and the two added tests were drafted with its help. I verified the call chain through
EmrContainerHook.check_query_statusandpoll_query_statusmyself, andran the test file locally both with and without the fix (2 failed / 9 passed before, 11 passed after). I understand the change and take responsibility for it.