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 changing hash during iteration #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Jul 5, 2024

The old code failed with:

can't add a new key into hash during iteration

The new code uses transform_keys to change all keys and then iterates all values. While this means it iterates twice, it should at least be safe.

Reported at: https://community.theforeman.org/t/foreman-proxy-monitoring-down-upgrading-foreman-from-3-10-to-3-11/38579/2

The old code failed with:

    can't add a new key into hash during iteration

The new code uses transform_keys to change all keys and then iterates
all values. While this means it iterates twice, it should at least be
safe.
@timogoebel
Copy link
Member

Nice catch, should this return the hash after transformation?

@ekohl
Copy link
Member Author

ekohl commented Jul 5, 2024

Right now it's modified in place and now used like that, but I suppose it could

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.

None yet

2 participants