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

Avoid mutable types as default args. #373

Merged
merged 1 commit into from
Dec 1, 2021

Conversation

abadger
Copy link
Member

@abadger abadger commented Nov 24, 2021

This change removes two places where we use a set as a default value.
Mutable containers should not be used as default arguments as they are
created when the function is defined (basically, the first time the
module is imported) and then that one instance is used anytime the
method is invoked without that argument specified. This means that
changes to the container will persist to the next time the function is
invoked.

This change seems to fix a bug we're seeing on oracle7 where we assemble
a list of packages to downgrade that includes gcc & gcc-c++ but then we find
that systemd is a protected package. At that point, the list of
packages to downgrade seems to revert to just systemd and we build up
the list again. This time, when we see that gcc is going to be
downgraded but gcc-c++ requires it, we do not decide to downgrade
gcc-c++. I haven't tracked down precisely why this is but I suspect that
gcc-c++ is getting placed in the default set for the excluded_pkgs
argument so that when we iterate over the pakcages the second time we
never re-add gcc-c++ to the list of pakcages to downgrade.

This change removes two places where we use a set as a default value.
Mutable containers should not be used as default arguments as they are
created when the function is defined (basically, the first time the
module is imported) and then that one instance is used anytime the
method is invoked without that argument specified.  This means that
changes to the container will persist to the next time the function is
invoked which could lead to bugs down the road.

I do not believe we're currently experiencing any bugs due to this as we
never seem to mutate the containers.  Instead, we use the data to make
new sets inside of the functions.
Copy link
Member

@bocekm bocekm left a comment

Choose a reason for hiding this comment

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

Thanks, @abadger!

@kokesak
Copy link
Member

kokesak commented Dec 1, 2021

I run the test suite manually:

There is still (known) issue with satellite, this one can be waived.

I also run the tests on the OL, however not all tests are completely functional yet. I just reviewed them manually

Overall, LGTM we can merge this PR.

@abadger abadger merged commit 8224bbd into oamg:main Dec 1, 2021
@abadger
Copy link
Member Author

abadger commented Dec 1, 2021

Thanks @kokesak @bocekm and @SpyTec for the reviews and testing! Now merged.

@abadger abadger deleted the remove-mutable-default branch December 1, 2021 15:53
@Venefilyn Venefilyn mentioned this pull request Dec 13, 2021
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.

4 participants