Migrate AzureBatchHook/Operator to azure-batch 15.x (track 2 SDK)#67600
Migrate AzureBatchHook/Operator to azure-batch 15.x (track 2 SDK)#67600arieleli01212 wants to merge 16 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
|
|
@arieleli01212 A few things need addressing before review — see our Pull Request quality criteria.
No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
…ack 2 SDK) The azure-batch package 15.x is a ground-up rewrite of the Azure SDK for Batch. The old BatchServiceClient and batch_auth module are gone; the new SDK exposes a flat BatchClient that uses azure-identity / AzureNamedKeyCredential. Changes: - Replace BatchServiceClient with BatchClient(endpoint, credential) - Replace batch_auth.SharedKeyCredentials with AzureNamedKeyCredential - Catch ResourceExistsError (azure.core) instead of BatchErrorException - Rename model types: PoolAddParameter → BatchPoolCreateOptions, JobAddParameter → BatchJobCreateOptions, TaskAddParameter → BatchTaskCreateOptions, ImageReference → BatchVmImageReference, PoolInformation → BatchPoolInfo, and Batch-prefixed task/job sub-types - Rename enums: ComputeNodeState → BatchNodeState, TaskState → BatchTaskState, TaskExecutionResult → BatchTaskExecutionResult (SCREAMING_SNAKE_CASE values) - Replace pool.list / compute_node.list / job.list / task.list hierarchy with flat client.list_nodes / list_tasks / list_jobs / list_supported_images calls - Use LRO methods begin_delete_pool / begin_delete_job / begin_terminate_job - Remove CloudServiceConfiguration support (Azure removed cloud-service VMs) - Drop os_family / os_version parameters from AzureBatchOperator (no longer applicable without CloudServiceConfiguration) - Lift azure-batch version cap from <15.0.0 to >=15.0.0 in pyproject.toml - Update all unit tests to use the new SDK classes and method signatures Closes apache#66466
- Remove BatchJobTerminateOptions from on_kill: not exported from azure.batch.models in 15.x; calling begin_terminate_job without a body parameter is sufficient and correct - Apply ruff formatting (collapsed single-line list comprehension) - Update uv.lock to pin azure-batch 15.1.0 (was 14.2.0) and fix dependencies (azure-core/isodate/typing-extensions instead of azure-common/msrestazure) and update the specifier to >=15.0.0
278240a to
d73c2f2
Compare
… allowlist - Fix MyPy: use 'if conn.login and conn.password' instead of 'all([...])' so MyPy can narrow str|None to str for AzureNamedKeyCredential - Fix MyPy: guard publisher/offer/sku_starts_with and image_reference fields against None before calling .lower()/.startswith() - Fix MyPy: use 'pool.target_dedicated_nodes or 0' to guard int|None in >= comparison - Fix MyPy: guard task.execution_info against None before accessing .result - Update known_airflow_exceptions.txt: operators/batch.py count 10->9 (removed one redundant raise during os_family removal) - Sync providers/microsoft/azure/README.rst requirements table
|
Oh, this is a full re-write which will generate breaking changes on users side. At least providers version need a major version bump. Can you please add a notice to changelog.rst for the provider similar like we had it recently in Google? https://github.com/apache/airflow/blob/main/providers/google/docs/changelog.rst?plain=1#L33 Note: Put the waring and migration details above the most recent version number, do NOT create a new one, this will be made by release manager once the provider release is cut. |
|
Done — added a breaking change notice with the migration details to |
|
Couple of CI errors. |
|
Quickest fix: git fetch upstream main && git rebase upstream/main
rm uv.lock && uv lock
git add uv.lock && git rebase --continue
git push --force-with-leaseAutomated nudge — ignore if you're not ready to rebase. This comment is updated in place on future |
|
@arieleli01212 A few things need addressing before review — see our Pull Request quality criteria.
No rush. Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you. |
# Conflicts: # providers/microsoft/azure/docs/changelog.rst
…5.x model names Main added deferrable mode for AzureBatchOperator (apache#66815) using the azure-batch 14.x model names (CloudTask, TaskState, TaskExecutionResult). Update the trigger and its tests to the 15.x track-2 names (BatchTask, BatchTaskState, BatchTaskExecutionResult) to stay consistent with the hook/operator migration in this PR.
….x API Main's deferrable AzureBatchOperator feature (apache#66815) used the azure-batch 14.x client surface (client.task.list, client.pool.get, client.compute_node.list). Migrate these to the 15.x track-2 flat methods (list_tasks, get_pool, list_nodes) to match the rest of this PR. - triggers/batch.py: hook.connection.task.list -> list_tasks - operators/batch.py: connection.pool.get -> get_pool, connection.compute_node.list -> list_nodes - hooks/batch.py: type: ignore[arg-type] on BatchClient credential (AzureIdentityCredentialAdapter is not a TokenCredential subtype; same convention as asb.py) - ruff format the trigger - known_airflow_exceptions.txt: operators/batch.py 9 -> 8 - spelling_wordlist.txt: add BatchClient, BatchNodeState
# Conflicts: # providers/microsoft/azure/docs/changelog.rst
configure_pool returns BatchPoolCreateOptions while connection.get_pool returns BatchPool; reusing the same local made mypy infer the narrower create-options type and reject the resize_errors access. Use a distinct variable for the fetched pool.
|
@arieleli01212 can you rebase and fix conflicts? |
…-sdk # Conflicts: # generated/provider_dependencies.json
|
Done, rebased on latest main and the conflict (the removed On the real Azure question — no, I haven't run this against a live Batch account, I don't have one set up. I validated it against the provider's unit tests, which I updated for the 15.x models ( |
We always prefer to validate against real life scenario. |
|
@arieleli01212 were you able to set it up? |
nailo2c
left a comment
There was a problem hiding this comment.
Hi, thanks for the PR, one question :)
| batch_client = BatchServiceClient(credentials, batch_url=batch_account_url) | ||
| batch_client = BatchClient( | ||
| endpoint=batch_account_url, | ||
| credential=credential, # type: ignore[arg-type] |
There was a problem hiding this comment.
I wonder why we need to ignore the type here.
According to the BatchClient doc, credential should be either AzureNamedKeyCredential or TokenCredential. If credential is an AzureIdentityCredentialAdapter, as shown on line 112, will it still work?
There was a problem hiding this comment.
cc @arieleli01212 can you address this review comment?
…-sdk # Conflicts: # providers/microsoft/azure/README.rst # providers/microsoft/azure/docs/changelog.rst # providers/microsoft/azure/docs/index.rst # providers/microsoft/azure/pyproject.toml # uv.lock
|
Rebased again on latest main — conflicts are resolved (mostly the azure deps in pyproject/uv.lock plus the changelog). I wasn't able to get a real Azure Batch account stood up on my end, so let's go with relying on the existing tests as you suggested. I did make sure the unit tests exercise the 15.x code paths I changed (the |
Description
The
azure-batchpackage underwent a complete API overhaul in version 15.x, moving from the old Azure SDK track 1 (BatchServiceClient,batch_auth) to track 2 (BatchClient, azure-identity). This PR updatesAzureBatchHookandAzureBatchOperatorto work with the new SDK and removes the<15.0.0upper bound cap that was explicitly blocking users from upgrading.Changes
hooks/batch.pyBatchServiceClientwithBatchClient(endpoint, credential)batch_auth.SharedKeyCredentialswithAzureNamedKeyCredentialResourceExistsError(fromazure.core.exceptions) instead ofBatchErrorExceptionPoolAddParameter→BatchPoolCreateOptions,JobAddParameter→BatchJobCreateOptions,TaskAddParameter→BatchTaskCreateOptions,ImageReference→BatchVmImageReference,PoolInformation→BatchPoolInfoBatchNodeState.IDLE,BatchTaskState.COMPLETED,BatchTaskExecutionResult.FAILUREclient.pool.add,client.compute_node.list, etc.) with the new flat API (client.create_pool,client.list_nodes, etc.)begin_delete_pool,begin_delete_job,begin_terminate_jobCloudServiceConfigurationsupport — Azure has retired cloud-service VM poolsoperators/batch.pybatch_job_manager_task,batch_job_preparation_task, etc. to use the newBatch-prefixed namesos_familyandos_versionparameters (no longer applicable withoutCloudServiceConfiguration)BatchNodeState.START_TASK_FAILED / UNUSABLE / IDLEon_kill()andclean_up()to use the LRO methodspyproject.tomlazure-batchconstraint from>=8.0.0,<15.0.0to>=15.0.0Tests
BatchClient, model types, and enum valuesRelates
Fixes the blocking comment left in
pyproject.tomlabout needing a hook rewrite before lifting the<15.0.0cap.closes: #66466
Testing
pytest providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_batch.pyand all tests passpytest providers/microsoft/azure/tests/unit/microsoft/azure/operators/test_batch.pyand all tests passImportant
🛠️ Maintainer triage note for @arieleli01212 · by
@potiuk· 2026-06-17 14:51 UTCHelpful heads-up from the maintainers — please address before this PR can be reviewed:
CI image checks / Build documentation (--docs-only),CI image checks / Build documentation (--spellcheck-only),CI image checks / Static checks,MyPy providers checks). Run them locally withprek run --all-files(orpre-commit run --all-files) and push the fixes.Non-DB tests: providers / Non-DB-prov::3.10:-amazon,celer...standard,Special tests / Latest Boto test: providers / All-prov:LatestBoto-Postgres:14:3.10:-amazon,celer...standard,Special tests / Pendulum2 test: providers / All-prov:Pendulum2-Postgres:14:3.10:-amazon,celer...standard,provider distributions tests / Compat 2.11.1:P3.10:… (+3 more). Reproduce and fix locally, then push.The ball is in your court — you've been assigned to this PR. Fix the above, then mark it Ready for review.
Automated triage — may be imperfect; a maintainer takes the next look.