Skip to content

Build DataprocCreateClusterOperator cluster_config from legacy kwargs after rendering - #70922

Open
bujjibabukatta wants to merge 2 commits into
apache:mainfrom
bujjibabukatta:fix/#70296-1
Open

Build DataprocCreateClusterOperator cluster_config from legacy kwargs after rendering#70922
bujjibabukatta wants to merge 2 commits into
apache:mainfrom
bujjibabukatta:fix/#70296-1

Conversation

@bujjibabukatta

Copy link
Copy Markdown
Contributor

Summary
DataprocCreateClusterOperator's deprecated keyword-based cluster
construction built cluster_config in init, using individually
templated kwargs (zone, cluster_name, project_id, ...) before rendering.

Root cause
ClusterGenerator(**kwargs).make() ran in init. These kwargs aren't
declared as template fields, so Jinja expressions passed this way never
got rendered before being baked into cluster_config.

Fix
Stash the raw kwargs in a new template field (_legacy_cluster_kwargs)
instead of building cluster_config immediately. Being a template field, it
survives DAG serialization and gets rendered automatically. cluster_config
is now built in execute(), after rendering.

closes: #70296

Was generative AI tooling used ?

  • Yes - Claude

Generated-by: Claude following the guidelines

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

Left 2 comments.

@mock.patch(DATAPROC_PATH.format("DataprocHook"))
def test_deprecated_kwargs_cluster_config_built_in_execute(self, mock_hook, to_dict_mock):
mock_hook.return_value.create_cluster.result.return_value = None
op = DataprocCreateClusterOperator(

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.

I think you need to wrap the operator construction like this in both tests to fix failing CI:

with pytest.warns(AirflowProviderDeprecationWarning):
    op = DataprocCreateClusterOperator(...)

mock_hook.return_value.create_cluster.result.return_value = None
op = DataprocCreateClusterOperator(
task_id=TASK_ID, region=GCP_REGION, project_id=GCP_PROJECT,
cluster_name="cluster_name", num_workers=2, zone="zone",

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.

The formatting of these arguments should be fixed by the linter.

@bujjibabukatta
bujjibabukatta force-pushed the fix/#70296-1 branch 2 times, most recently from 61df2d0 to 724860b Compare August 3, 2026 07:40
@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

Hi @SameerMesiah97 thanks for catching both — fixed. Wrapped the operator
construction in pytest.warns(AirflowProviderDeprecationWarning) in both
tests, and reformatted to one argument per line.

Separately: Static checks keeps failing on validate-operators-init, flagging
files unrelated to this PR (e.g. glacier.py, whose init is a plain
assignment with no logic at all). I've reset onto current main and
re-cherry-picked a few times now — it passes briefly then fails the same way
again, which looks like a merge-base/timing issue against how fast main is
moving, not anything in this diff. Would appreciate a quick look or merge to
break the cycle.

**kwargs,
) -> None:
# TODO: remove one day
self._legacy_cluster_kwargs: dict | None = None

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.

The kwargs functionality is deprecated and scheduled for deletion, so what the point bringing them into templated fields, the original issue #70296 states

Template fields are rendered after an operator's constructor runs. Any logic applied to a template-field parameter's value inside init — validation, type checks, transformation, string interpolation — therefore operates on the un-rendered Jinja expression, not the real value.

So whats the point to bringing them into templating fields?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@olegkachur-e Good point. They're deprecated but still around, so they should still work right until they're actually removed. Right now they don't — cluster_config gets built in init before rendering happens, so any templated value just doesn't get filled in. This fix takes care of that in the meantime.

If you'd rather I just remove the kwargs path instead of fixing it, I'm okay with that too.

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

Labels

area:dev-tools area:providers backport-to-v3-3-test Backport to v3-3-test provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Move template-field validation/transformation out of operator __init__ (exemption-list burn-down)

3 participants