Skip to content

Validate Cloud Function deploy body after template rendering - #70531

Open
mitre88 wants to merge 1 commit into
apache:mainfrom
mitre88:fix-cloud-function-deploy
Open

Validate Cloud Function deploy body after template rendering#70531
mitre88 wants to merge 1 commit into
apache:mainfrom
mitre88:fix-cloud-function-deploy

Conversation

@mitre88

@mitre88 mitre88 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Part of the template-field validation burn-down tracked in #70296.

CloudFunctionDeployFunctionOperator lists body, location, and api_version in template_fields, but __init__ validated the body, ran ZipPathPreprocessor.preprocess_body() (which both validates and mutates the body), and constructed GcpBodyFieldValidator pinned to the un-rendered api_version. A fully templated body crashed with AttributeError at parse time inside the preprocessor. All of this now runs at the start of execute() against the rendered values.

The missing-location/body truthiness checks and the zip-path exclusivity rules depend on rendered values (an expression rendering to an empty string must count as missing), so per the discussion in #70505 these are genuine value reads, not provision checks.

Tests: converted the four construction-time raise tests to execute-time, and added test_templated_body_deploys_after_rendering, which constructs the operator with a templated body (previously a parse-time crash) and deploys once the field holds the rendered value — it fails against the previous implementation. The class is removed from the exemption list and the validate-operators-init check passes locally.


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Fable 5)

Generated-by: Claude Code (Fable 5) following the guidelines

@boring-cyborg boring-cyborg Bot added area:dev-tools area:providers backport-to-v3-3-test Backport to v3-3-test provider:google Google (including GCP) related issues labels Jul 27, 2026
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 28, 2026

@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 — correct move. body is a template field, so GcpBodyFieldValidator in __init__ was validating the un-rendered value: a templated body could never pass validation, and a literal bad one broke Dag parsing instead of failing the task. Constructing the validator and the ZipPathPreprocessor in execute and running _validate_inputs() there is the right shape.

test_templated_body_deploys_after_rendering is a good addition — asserting create_new_function.assert_called_once() after a rendered body proves the happy path still works, not just that the failure path raises.

One robustness point inline about an attribute that no longer exists until execute runs.


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

}

def execute(self, context: Context):
self.zip_path_preprocessor = ZipPathPreprocessor(self.body, self.zip_path)

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.

self.zip_path_preprocessor is now only assigned here, so between construction and the first execute the attribute doesn't exist at all — any access raises AttributeError rather than returning something sensible. That affects subclasses, tests, and anything introspecting the operator between parse and run.

Note you've already handled the sibling case correctly: self._field_validator: GcpBodyFieldValidator | None = None is still initialised in __init__ and merely reassigned in execute. Doing the same for the preprocessor — declare it as None in __init__, build it here — would make the two consistent and keep the operator's attribute surface stable from construction onwards.


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

Rebased onto current main. Move body/location validation and zip
preprocessing into execute so Jinja-templated body is checked after render.
@mitre88
mitre88 force-pushed the fix-cloud-function-deploy branch from 8319802 to 3280b64 Compare August 1, 2026 02:24
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 ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants