Skip to content

Support max retries in Azure Batch operator - #73071

Open
AbarnaaSree wants to merge 2 commits into
apache:mainfrom
AbarnaaSree:fix/72982-azure-batch-max-retries
Open

AbarnaaSree wants to merge 2 commits into
apache:mainfrom
AbarnaaSree:fix/72982-azure-batch-max-retries

Conversation

@AbarnaaSree

@AbarnaaSree AbarnaaSree commented Sep 13, 2026 •

Copy link
Copy Markdown

Summary

  • Add retry_total support to AzureBatchHook.
  • Pass batch_max_retries from AzureBatchOperator to the Azure Batch SDK retry policy.
  • Omit retry_total when unset so the Azure SDK default behavior is preserved.
  • Add regression coverage for configured and default retry behavior.

The operator and hook default to None so existing users retain the Azure SDK's default retry behavior unless batch_max_retries is explicitly set.

related: #72982


Was generative AI tooling used to co-author this PR?
  • Yes (ChatGPT)

@boring-cyborg

boring-cyborg Bot commented Sep 13, 2026

Copy link
Copy Markdown

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
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@shahar1 shahar1 changed the title feat: support max retries in Azure Batch operator Support max retries in Azure Batch operator Sep 13, 2026

@bingqin2 bingqin2 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.

Thanks for picking this up, it has the right shape. A few things before a maintainer looks at it:

  1. retry_total=None must not reach the client. With the new default the operator builds the hook with retry_total=None, and the hook passes that straight to BatchClient(...). azure-core takes an explicit None over its own default: the retry policy ends up with total_retries = None, and its increment() runs settings["total"] -= 1 on the first retry, which raises TypeError (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 BatchClient is called without retry_total when the hook default is used.

  2. closes: #72982 should be related: #72982. That issue tracks several parameters, and merging this as is would auto-close it.

  3. Docstrings. The operator docstring still says "Default is 3" for batch_max_retries (operators/batch.py, line 70). With None the 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. AzureBatchHook gained retry_total, but the class docstring (hooks/batch.py, line 45) does not list it.

  4. The Static checks failure is the commit message. Airflow rejects Conventional Commits prefixes, so feat: support max retries in Azure Batch operator has to become plain prose, for example Honor batch_max_retries in AzureBatchOperator. git commit --amend, then force-push the branch.

  5. Optional: a test on the operator side that batch_max_retries reaches the hook (op.hook.retry_total == 5, or patch AzureBatchHook in the operator module and assert its kwargs), so the wiring is covered end to end.

@AbarnaaSree
AbarnaaSree force-pushed the fix/72982-azure-batch-max-retries branch from f2f4255 to 5bcf649 Compare September 13, 2026 16:57

@Vamsi-klu Vamsi-klu left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

​

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

  1. Deferrable mode still ignores it. AzureBatchTrigger.run() builds its own AzureBatchHook(azure_batch_conn_id=...) without retry_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. With deferrable=True, batch_max_retries=0, only the pool/job/task creation in execute() honours the 0. Could you add a retry argument to the trigger's __init__ and serialize(), pass it from the operator's defer() call, and cover it with a test?
  2. The default quietly changes from 3 to the SDK default. Before #71071, execute() applied batch_max_retries (documented "Default is 3") to the client's retry policy. With None, a Dag that never set it now gets the SDK default of 10 retries. Either keep 3 as the default, or keep None and update the docstring plus providers/microsoft/azure/docs/changelog.rst so users see the change.

Drafted-by: Claude Code (Opus 5.5); reviewed by @potiuk before posting

@AbarnaaSree

Copy link
Copy Markdown
Author

Thanks for the feedback! I've updated the implementation to address both points:

  1. Added retry_total support to AzureBatchTrigger, included it in trigger serialization, and passed batch_max_retries from the operator's deferrable execution. I've also added a test to verify that the retry setting is forwarded to the hook.
  2. Retained the default value of batch_max_retries as 3 and documented that setting it to None uses the Azure SDK default.

I've verified the Python syntax and ran git diff --check successfully.

The changes have been pushed to the PR. Thank you!

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants