fix: guard against a None action in ZPA isolation rule updates - #576
Open
hackerboey wants to merge 1 commit into
Open
fix: guard against a None action in ZPA isolation rule updates#576hackerboey wants to merge 1 commit into
hackerboey wants to merge 1 commit into
Conversation
update_isolation_rule and update_isolation_rule_v2 both declare action
as optional (action: str = None) but build their payload with an
unguarded action.upper(). A partial update that omits action raises
AttributeError: 'NoneType' object has no attribute 'upper' before any
request is made, so neither method can be used for a partial update.
Both now use the guarded form the sibling update methods in this module
already use, e.g. update_access_rule:
"action": action.upper() if action else None
None is what the surrounding keys (name, description,
zpnIsolationProfileId) already resolve to when omitted, so the payload
stays internally consistent and nothing changes when action is supplied.
The remaining unguarded action.upper() sites in this module take action
as a required positional parameter, so omitting it raises TypeError
rather than AttributeError; those are left alone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #574
PolicySetControllerAPI.update_isolation_ruleandupdate_isolation_rule_v2both declareaction: str = None, but build the payload with an unguardedaction.upper(). A partialupdate that does not pass
actiontherefore raisesbefore any request is built, so those methods cannot be used for a partial update at all.
Why this shape of fix
The same file already guards the identical expression elsewhere, e.g.
so this looks like an internal inconsistency rather than a deliberate difference. The change
makes the two unguarded sites match the guarded form already used nearby — no new pattern is
introduced, and behaviour for a caller who does pass
actionis unchanged.Test
Adds
tests/unit/test_zpa_policies.py, following the layout and style of the existing flattests/unit/test_*.pyfiles. It mocks the request executor, so no credentials or network accessare needed — the failure occurs while building the payload.
Verified against this branch: 2 passed. Verified against
master'spolicies.py: 2 failedwith the
AttributeErrorabove, so it is a genuine regression guard rather than a tautology.Full
tests/unit: 601 passed.ruff check,ruff check --select Iandblack --check --line-length 127are all clean.Diff is +52/-2 across two files, and the change to
policies.pyis two lines. Happy to rescopeif you would prefer a different guard form, or to extend it to other optional fields.