pavansai1997 opened a new pull request, #77584: URL: https://github.com/apache/airflow/pull/77584
On Airflow 3.3+, a non-deferrable `LivyOperator` with `polling_interval > 0` waits through `ResumableJobMixin.execute_resumable` (`durable=True` by default, #68956). When a retry finds the stored batch still running, the mixin reconnects: it returns what `poll_until_complete` returns and does not call `get_job_result`. The Redshift Data, Databricks and Snowflake operators handle this in `poll_until_complete`, and their comments say so. In `LivyOperator` only `get_job_result` returned the batch id and pushed the `app_id` XCom, so after a reconnect: - `execute()` returned `None` instead of the batch id; - no `app_id` XCom was pushed. The XComs of the previous try are cleared when a new try starts, so downstream tasks pulling the return value or `app_id` got `None` although the batch succeeded. A mapped task expanding over the operator's output would make the reconnected try fail with `XComForMappingNotPushed`. Running `execute()` with a mocked hook and task state store, for the three durable paths: | Path | before | after | |---|---|---| | fresh submit | returns batch id, 1 `app_id` push | same | | retry, stored batch succeeded | returns batch id, 1 `app_id` push | same | | retry, stored batch running (reconnect) | returns `None`, no `app_id` push | returns batch id, 1 `app_id` push | With this change, `poll_until_complete` pushes `app_id` after the batch succeeds, `get_job_result` only pushes it when `poll_until_complete` has not already done so for that batch (the already-succeeded path), and `execute()` returns `self._batch_id`, which every path sets. A fresh run still calls `get_batch` once. The existing reconnect tests replace `poll_until_complete` with a stub and do not check the result. The new parametrized test runs the real `poll_until_complete` on the three paths, with a stored batch id different from the one a new submission would get, and checks the returned id, the batch the `app_id` was read from, and that `app_id` is pushed once. The reconnect case fails without this change. `test_poll_until_complete_sets_batch_id_for_on_kill` now passes a `ti` in the context, since `poll_until_complete` pushes the XCom. The bug shipped in `apache-airflow-providers-apache-livy` 4.6.0. --- ##### Was generative AI tooling used to co-author this PR? - [X] Yes — Code Puppy Generated-by: Code Puppy following [the guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions) -- 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]
