Fix UnboundLocalError when enabling azure-rbac without custom-locations in connectedk8s #1
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.
This PR fixes a critical UnboundLocalError that occurs when using
az connectedk8s enable-featuresto enable only theazure-rbacfeature without enablingcustom-locations.Problem
The
enable_featuresfunction insrc/connectedk8s/azext_connectedk8s/custom.pyreferenced local variablesfinal_enable_clandcustom_locations_oidthat were only defined inside theif enable_cl:conditional block. When users enabled azure-rbac without custom-locations (enable_clis False), these variables were never initialized, causing an UnboundLocalError when the function tried to build the final helm command.Root Cause
The variables were defined conditionally but referenced unconditionally:
Solution
Added defensive initialization of these variables with safe defaults before any conditional assignment:
This ensures the variables are always available when referenced later in the function, regardless of which features are enabled.
Testing
This is a minimal, safe fix that preserves all existing behavior while eliminating the runtime error.
Created from VS Code via the GitHub Pull Request extension.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.