Skip to content

Validate AzureVirtualMachineStateSensor target_state after rendering - #70329

Merged
shahar1 merged 2 commits into
apache:mainfrom
1fanwang:fix-azure-vmstate-sensor-init
Jul 24, 2026
Merged

Validate AzureVirtualMachineStateSensor target_state after rendering#70329
shahar1 merged 2 commits into
apache:mainfrom
1fanwang:fix-azure-vmstate-sensor-init

Conversation

@1fanwang

@1fanwang 1fanwang commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

target_state is a template field, so it is rendered after __init__ runs. AzureVirtualMachineStateSensor validated it against VALID_STATES and raised ValueError in the constructor, so a templated target_state could never be built — __init__ saw the un-rendered Jinja expression and rejected it:

ValueError: Invalid target_state: {{ params.state }}. Must be one of ['deallocated', 'deallocating', 'running', 'starting', 'stopped']

Store target_state verbatim in the constructor and move the check into poke(), which runs after rendering (both the synchronous and deferrable paths reach poke() before using the value).

related: #70296

Testing Done

Reverting only the source and running the new tests reproduces the bug:

test_templated_target_state_constructs FAILED
  ValueError: Invalid target_state: {{ params.state }}. Must be one of [...]
test_invalid_target_state_rejected_at_poke FAILED

With the fix, test_compute.py: 9 passed. validate_operators_init.py on the sensor exits 0 (the constructor no longer reads the template field).


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI following the guidelines

target_state is a template field, so it is rendered after __init__ runs. The
constructor validated it against VALID_STATES and raised ValueError there, so a
templated target_state (e.g. "{{ params.state }}") could never be built: __init__
saw the un-rendered expression and rejected it. Move the check into poke(), which
runs after rendering, and store target_state verbatim in the constructor.

related: apache#70296
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang marked this pull request as ready for review July 24, 2026 06:23
@shahar1
shahar1 merged commit d4622c7 into apache:main Jul 24, 2026
126 of 140 checks passed
@shahar1 shahar1 removed the backport-to-v3-3-test Backport to v3-3-test label Jul 24, 2026
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.

2 participants