Repository navigation
Support max retries in Azure Batch operator - #73071
AbarnaaSree wants to merge 2 commits into
Conversation
|
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
|
bingqin2
left a comment
There was a problem hiding this comment.
Thanks for picking this up, it has the right shape. A few things before a maintainer looks at it:
-
retry_total=Nonemust not reach the client. With the new default the operator builds the hook withretry_total=None, and the hook passes that straight toBatchClient(...). azure-core takes an explicitNoneover its own default: the retry policy ends up withtotal_retries = None, and itsincrement()runssettings["total"] -= 1on the first retry, which raisesTypeError(checked against azure-core 1.41.0). So every transient error would fail immediately instead of being retried, for everyone who leaves the parameter unset. Pass the kwarg only when it is set, for example:client_kwargs = {} if self.retry_total is None else {"retry_total": self.retry_total} batch_client = BatchClient(endpoint=batch_account_url, credential=credential, **client_kwargs)
and add a test asserting that
BatchClientis called withoutretry_totalwhen the hook default is used. -
closes: #72982should berelated: #72982. That issue tracks several parameters, and merging this as is would auto-close it. -
Docstrings. The operator docstring still says "Default is 3" for
batch_max_retries(operators/batch.py, line 70). WithNonethe Azure SDK default applies, which is 10 retries, and it is worth stating that this keeps today's behaviour for anyone who has not set the parameter.AzureBatchHookgainedretry_total, but the class docstring (hooks/batch.py, line 45) does not list it. -
The Static checks failure is the commit message. Airflow rejects Conventional Commits prefixes, so
feat: support max retries in Azure Batch operatorhas to become plain prose, for exampleHonor batch_max_retries in AzureBatchOperator.git commit --amend, then force-push the branch. -
Optional: a test on the operator side that
batch_max_retriesreaches the hook (op.hook.retry_total == 5, or patchAzureBatchHookin the operator module and assert its kwargs), so the wiring is covered end to end.
f2f4255 to
5bcf649
Compare
5bcf649 to
7955008
Compare
potiuk
left a comment
There was a problem hiding this comment.
Thanks, re-wiring batch_max_retries after the 15.x SDK migration is the right idea, and forwarding retry_total only when it's set keeps 0 working. Two things before this can go in:
- Deferrable mode still ignores it.
AzureBatchTrigger.run()builds its ownAzureBatchHook(azure_batch_conn_id=...)withoutretry_total, and the trigger neither takes nor serializes a retry setting. So once the task defers, all the task-completion polling in the triggerer, which is most of the job's runtime, uses the SDK default. Withdeferrable=True, batch_max_retries=0, only the pool/job/task creation inexecute()honours the 0. Could you add a retry argument to the trigger's__init__andserialize(), pass it from the operator'sdefer()call, and cover it with a test? - The default quietly changes from 3 to the SDK default. Before #71071,
execute()appliedbatch_max_retries(documented "Default is 3") to the client's retry policy. WithNone, a Dag that never set it now gets the SDK default of 10 retries. Either keep3as the default, or keepNoneand update the docstring plusproviders/microsoft/azure/docs/changelog.rstso users see the change.
Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting
|
Thanks for the feedback! I've updated the implementation to address both points:
I've verified the Python syntax and ran The changes have been pushed to the PR. Thank you! |
|
|
||
| @pytest.mark.asyncio | ||
| async def test_trigger_passes_retry_total_to_hook(self): | ||
| completed_task = mock.MagicMock() |
There was a problem hiding this comment.
Could you specify spec/autospec here? Otherwise, it will mock everything.
| @@ -218,6 +219,27 @@ def setup_test_cases(self, mocked_batch_client, create_mock_connections): | |||
| timeout=2, | |||
| ) | |||
|
|
|||
There was a problem hiding this comment.
Could you modify the test_execute_defers test to include verification of the operator -> trigger value set?
| when the Compute Node is restarted. | ||
| :param batch_max_retries: The number of times to retry this batch operation before it's | ||
| considered a failed operation. Default is 3 | ||
| :param batch_max_retries: The maximum number of retries for the batch operation. |
There was a problem hiding this comment.
| :param batch_max_retries: The maximum number of retries for the batch operation. | |
| :param batch_max_retries: The maximum number of retries for the Azure Batch requests. |
| end_time: float, | ||
| poll_interval: int = 30, | ||
| retry_total: int | None = None, | ||
| ): |
There was a problem hiding this comment.
| ): | |
| ) -> None: |
line not changed here, but I noticed that we don't have here type annotation.
Not really. Hook has a default of |
Summary
retry_totalsupport toAzureBatchHook.batch_max_retriesfromAzureBatchOperatorto the Azure Batch SDK retry policy.retry_totalwhen unset so the Azure SDK default behavior is preserved.The operator and hook default to
Noneso existing users retain the Azure SDK's default retry behavior unlessbatch_max_retriesis explicitly set.related: #72982
Was generative AI tooling used to co-author this PR?