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

[tech debt] Avoid recursive include of DEFAULT_SETTINGS, sanity test #13236

Merged
merged 3 commits into from
Apr 20, 2023

Conversation

AlanCoding
Copy link
Member

SUMMARY

I told @john-westcott-iv this was going to bother me, but I wasn't going to make a PR to change it until I saw this failure.

Traceback (most recent call last):
  File "/awx_devel/awx/main/tests/unit/test_settings.py", line 22, in test_default_settings
    raise Exception(f'Default setting for {k} does not match:\nsnapshot: {snapshot_val}\ndefault: {default_val}')
Exception: Default setting for DEFAULTS_SNAPSHOT does not match:
...

Wait, what? The snapshot value for DEFAULTS_SNAPSHOT doesn't match? That doesn't make any sense. We got that snapshot value from the snapshot dictionary! Did this dict save a copy of itself... inside itself?

Yes.

ISSUE TYPE
  • Bug, Docs Fix or other nominal change
COMPONENT NAME
  • API

DEFAULTS_SNAPSHOT[setting] = copy.deepcopy(getattr(this_module, setting))

del local_vars
del this_module
Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to del these because we do use dir on the settings module in our settings wrapper:

https://github.com/ansible/awx/blob/devel/awx/conf/settings.py#L474

and I just don't want to pollute that namespace with more variables that should be internal to logic inside of settings. It would be impractical to add an __ALL__ to this module. Also, the original recursive copy here was because of lack of awareness of what things hanging out in locals(). We avoid copying lowercase vars in the loop, but I prefer to explicitly exclude them from the namespace, as they should not be public.

@AlanCoding
Copy link
Member Author

Integration tests are passing, so I'm happy with this myself now.

awx/main/tests/unit/test_settings.py Show resolved Hide resolved
awx/main/tests/unit/test_settings.py Outdated Show resolved Hide resolved
awx/settings/development.py Outdated Show resolved Hide resolved
awx/settings/development.py Outdated Show resolved Hide resolved
@AlanCoding
Copy link
Member Author

@john-westcott-iv I believe I updated based on all your review comments. How does it look now?

@AlanCoding AlanCoding changed the title Avoid recursive include of DEFAULT_SETTINGS, sanity test [tech debt] Avoid recursive include of DEFAULT_SETTINGS, sanity test Apr 13, 2023
@AlanCoding AlanCoding self-assigned this Apr 13, 2023
@AlanCoding AlanCoding merged commit 0867221 into ansible:devel Apr 20, 2023
14 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.

None yet

2 participants