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

feat: allow classes that inherit Resource to disable __setattr__ validation #3047

Merged
merged 1 commit into from
Mar 21, 2023
Merged

feat: allow classes that inherit Resource to disable __setattr__ validation #3047

merged 1 commit into from
Mar 21, 2023

Conversation

pradrx
Copy link
Contributor

@pradrx pradrx commented Mar 21, 2023

Issue #, if available

Description of changes

In the Resource class, we have an override on __setattr__ that checks if the attribute that is being modified is in the property_types dictionary or _keywords set (logical_id, relative_id, etc...).

Because of this, we cannot create class variables that can be modified after initialization. An example of why this can be annoying for developers is if you have a state that you would like to track throughout the class, you must do so internally with a local variable. This change adds a new boolean attribute to Resource, validate_setattr. If set to True (which is default value), then validation will be performed as normal. When it's false, it will bypass the property_types and _keywords check and allow you to modify other class variables without trouble.

Description of how you validated changes

Added unit tests where I created a dummy resource that inherits from Resource, with validate_setattr set to True and False in different cases.

Checklist

Examples?

Please reach out in the comments if you want to add an example. Examples will be
added to sam init through aws/aws-sam-cli-app-templates.

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

@pradrx pradrx requested a review from a team as a code owner March 21, 2023 23:09
@hoffa hoffa merged commit e4b6e77 into aws:develop Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants