Fix aws ecs deploy not defaulting an empty --cluster to "default" - #10557
Open
Adityaj0 wants to merge 1 commit into
Open
Fix aws ecs deploy not defaulting an empty --cluster to "default"#10557Adityaj0 wants to merge 1 commit into
Adityaj0 wants to merge 1 commit into
Conversation
ECSClient.get_service_details() defaults the cluster to "default" with:
if cluster is None or '':
cluster = 'default'
Operator precedence makes this `(cluster is None) or ('')`. The bare
string literal '' is always falsy, so it never changes the outcome of
the `or` - the check is silently equivalent to `if cluster is None:`.
--cluster is documented as: "If you do not specify a cluster, the
'default' cluster is assumed." That holds when --cluster is omitted
(argparse leaves it None), but not when a caller passes --cluster ""
(e.g. a CI/CD pipeline doing `--cluster "$CLUSTER_NAME"` where the
variable is unset), since '' is not None. The empty string is then
sent straight through to DescribeServices instead of falling back to
the default cluster the command promises.
Replace the condition with `if not cluster:`, which treats None and ''
identically and matches the documented behavior in both cases. Added
regression tests for get_service_details, which previously had none.
Fixes aws#10556
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 task
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.
Issue
Fixes #10556
Description of changes
ECSClient.get_service_details()(used byaws ecs deploy) defaults an unspecified cluster to"default"with:This parses as
(cluster is None) or (''). The bare''literal is always falsy, so it never affects theor— the whole condition is silently equivalent toif cluster is None:. Theor ''is dead code.--cluster's help text says: "If you do not specify a cluster, the 'default' cluster is assumed." That's true when--clusteris omitted (argparse leaves itNone), but not when a caller passes--cluster ""— e.g. a CI/CD pipeline running--cluster "$CLUSTER_NAME"where the variable is unset or empty. In that caseclusteris'', notNone, so the fallback is skipped and the empty string is sent straight through toDescribeServicesinstead of resolving to the default cluster the command documents.Fix:
if not cluster:, which treatsNoneand''identically and matches the documented behavior in both cases.Testing
get_service_details()had no existing test coverage at all for the cluster-defaulting behavior (only theECSClientconstructor/config was tested intest_ecsclient.py). Added three tests totests/unit/customizations/ecs/test_ecsclient.py:--clusteromitted (None) → falls back todefault(already worked, now covered)--cluster ""→ falls back todefault(was broken, now fixed)--cluster my-cluster→ passed through unchanged (already worked, now covered)I confirmed the empty-string test fails with
AssertionError: '' != 'default'on unmodifiedv2and passes with the fix.tests/unit/customizations/ecs/+tests/functional/ecs/: 275 passedruff check/ruff format --checkon both touched files: clean