Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sam delete not picking up global parameters from samconfig.yaml #6541

Merged
merged 5 commits into from
Jan 19, 2024

Conversation

sidhujus
Copy link
Contributor

@sidhujus sidhujus commented Jan 9, 2024

Which issue(s) does this change fix?

#6449

Why is this change necessary?

the delete command was doing its own parsing of the config file

How does it address the issue?

switch to use the decorator that reads values from config files and passes those to the function

What side effects does this change have?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

lucashuy
lucashuy previously approved these changes Jan 11, 2024
Comment on lines -91 to -95
if not self.stack_name:
self.stack_name = config_options.get("stack_name", None)
# If the stack_name is same as the one present in samconfig file,
# get the information about parameters if not specified by user.
if self.stack_name and self.stack_name == config_options.get("stack_name", None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to have this logic in the delete code somewhere? If I remember correctly, the config decorator will load all parameters into the click context.

So if the options in the config were all related to stack xyz, and I instead did sam delete --stack-name abc, will it use the parameters related to xyz, for stack abc?

The previous behaviour looks like it won't, and instead will just not set the other options listed below, but feel free to call this out if's a non issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch. We may run integration tests manually to see if there are some tests which validates this behavior.

It is also weird that we only set these parameters if stack name matches, if not we are just leaving that as it is, which might fail the command there 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it out with my changes, and the behaviour now is that it will prioritize parameters passed in via the cli options over config values, but theres no logic to skip setting the other variables if the stack name differs between the config and cli parameter

@@ -149,14 +121,12 @@ def test_delete_no_user_input(
def test_delete_context_valid_execute_run(self, get_boto_client_provider_mock, patched_click_get_current_context):
patched_click_get_current_context = MagicMock()
with DeleteContext(
stack_name=None,
stack_name="test",
Copy link
Contributor

@lucashuy lucashuy Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did something else get read in for these values to be changed to test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it was reading in some values from a config file somewhere, but since all that happens outside of the context now i had to set the values here

@lucashuy lucashuy self-requested a review January 11, 2024 23:27
@lucashuy lucashuy dismissed their stale review January 11, 2024 23:27

Accidentially approved

@@ -73,26 +67,6 @@ def test_delete_context_enter(self, get_boto_client_provider_mock):
)
),
)
@patch("samcli.commands.delete.delete_context.click.get_current_context")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we remove this test? This should resolve as it was written since those are the provided values right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're using the decorator to read the config and its values all the parsing of the config file happens there instead, and the DeleteContext just has the values passed in now instead of doing any parsing.

Copy link
Contributor

@hnnasit hnnasit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, sam delete configuration should be aligned with sam deploy. Changes look good to me overall.

@sidhujus sidhujus added this pull request to the merge queue Jan 19, 2024
Merged via the queue into aws:develop with commit 4aef340 Jan 19, 2024
55 checks passed
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.

5 participants