nailo2c opened a new pull request, #67021:
URL: https://github.com/apache/airflow/pull/67021
closes: #37217
# How
1. Add `job` to `template_fields`.
2. Add a unit test for template rendering to prevent regression in the
future.
+ Reproduction Dag
```python
from datetime import datetime
import os
from google.cloud import batch_v1
from airflow.models.dag import DAG
from airflow.providers.google.cloud.operators.cloud_batch import (
CloudBatchSubmitJobOperator,
)
PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "<my-project-id>")
REGION = "us-central1"
def _build_job_with_template() -> batch_v1.Job:
runnable = batch_v1.Runnable()
runnable.container = batch_v1.Runnable.Container()
runnable.container.image_uri = "gcr.io/google-containers/busybox"
runnable.container.entrypoint = "/bin/sh"
runnable.container.commands = [
"-c",
"echo logical_date={{ ds }} run_id={{ run_id }}",
]
task = batch_v1.TaskSpec()
task.runnables = [runnable]
resources = batch_v1.ComputeResource()
resources.cpu_milli = 2000
resources.memory_mib = 16
task.compute_resource = resources
task.max_retry_count = 1
group = batch_v1.TaskGroup()
group.task_count = 1
group.task_spec = task
policy = batch_v1.AllocationPolicy.InstancePolicy()
policy.machine_type = "e2-small"
instances = batch_v1.AllocationPolicy.InstancePolicyOrTemplate()
instances.policy = policy
allocation_policy = batch_v1.AllocationPolicy()
allocation_policy.instances = [instances]
job = batch_v1.Job()
job.task_groups = [group]
job.allocation_policy = allocation_policy
job.logs_policy = batch_v1.LogsPolicy()
job.logs_policy.destination =
batch_v1.LogsPolicy.Destination.CLOUD_LOGGING
return job
with DAG(
dag_id="repro_37217",
start_date=datetime(2026, 1, 1),
schedule=None,
catchup=False,
) as dag:
CloudBatchSubmitJobOperator(
task_id="submit_with_template",
project_id=PROJECT_ID,
region=REGION,
job_name="repro-37217-{{ ts_nodash | lower }}",
job=_build_job_with_template(),
)
```
# What
### Before the fix
GCP Batch logs:
<img width="1419" height="809" alt="37217_repro_gcp_batch_before_fix"
src="https://github.com/user-attachments/assets/d7ad0fa0-2260-4661-8c30-49694a6ea848"
/>
### After the fix
<img width="1436" height="809" alt="37217_repro_gcp_batch_after_fix"
src="https://github.com/user-attachments/assets/8379708e-23ed-41e1-99e0-44be560fe4c8"
/>
<br><br>
---
##### Was generative AI tooling used to co-author this PR?
<!--
If generative AI tooling has been used in the process of authoring this PR,
please
change below checkbox to `[X]` followed by the name of the tool, uncomment
the "Generated-by".
-->
- [x] Yes (please specify the tool below)
Generated-by: Claude Opus 4.7 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]