1fanwang opened a new pull request, #70329:
URL: https://github.com/apache/airflow/pull/70329

   `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
   
   <details><summary>Testing Done</summary>
   
   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).
   
   </details>
   


-- 
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]

Reply via email to