Skip to content

Updated dict .keys() and .values() indexed calls for py3 - #56243

Merged
dwoz merged 24 commits into
saltstack:masterfrom
raddessi:master.py3-beacons
May 19, 2020
Merged

dwoz merged 24 commits into
saltstack:masterfrom
raddessi:master.py3-beacons

Conversation

@raddessi

Copy link
Copy Markdown
Contributor

What does this PR do?

Update all indexed dict .keys() and .values() calls I could find to be compatible with python 3, since both dict_keys and dict_values objects are not subscriptable in python 3.

What issues does this PR fix or reference?

I found this from napalm beacons not working when running in py3.

Previous Behavior

Napalm beacons would fail to run on py3.

New Behavior

Napalm beacons work as expected

Tests written?

No

Commits signed with GPG?

No

@raddessi
raddessi requested a review from a team as a code owner February 25, 2020 05:08
@ghost
ghost requested a review from cmcmarrow February 25, 2020 05:08

@s0undt3ch s0undt3ch left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, generating a whole list just to get one value seems like a bad performance move(if the list gets big enough).

next(iter(dict.keys()))

?
This only works for the zero indexed list accesses.

@raddessi

raddessi commented Feb 25, 2020 via email

Copy link
Copy Markdown
Contributor Author

@raddessi

Copy link
Copy Markdown
Contributor Author

OK I made that change anywhere on the codebase it seemed relevant except for the tests. I only saw exception handling in 2 locations and those were both updated from IndexError to StopIteration

@raddessi

Copy link
Copy Markdown
Contributor Author

If this is approved it can deprecate #53433 as this fixes the same issue across all modules not just napalm beacons. I KNEW I wasn't going crazy.. at least not yet anyway. This felt like total deja vu

@raddessi

raddessi commented Feb 26, 2020 •

Copy link
Copy Markdown
Contributor Author

Hmm.. #56232 brings up the point that this is also relevant for .items()[:] indexing as well.. I'm going to look for occurrences of those also

@raddessi

Copy link
Copy Markdown
Contributor Author

Not many occurrences of that actually, hopefully that last commit covers it

@raddessi
raddessi requested a review from s0undt3ch February 26, 2020 21:35
cmcmarrow
cmcmarrow previously approved these changes Mar 18, 2020
@raddessi

Copy link
Copy Markdown
Contributor Author

Is there any way we could get this in to 3000.1?

@raddessi
raddessi requested a review from s0undt3ch March 30, 2020 18:04
s0undt3ch
s0undt3ch previously approved these changes Mar 30, 2020

@s0undt3ch s0undt3ch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good

@raddessi

raddessi commented Apr 6, 2020

Copy link
Copy Markdown
Contributor Author

I've set up a key for signing future commits now, can we skip this error here or is there a way to sign past commits?

@raddessi
raddessi requested a review from DmitryKuzmenko April 6, 2020 16:42
DmitryKuzmenko
DmitryKuzmenko previously approved these changes Apr 6, 2020

@DmitryKuzmenko DmitryKuzmenko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perfect

@raddessi

raddessi commented Apr 7, 2020

Copy link
Copy Markdown
Contributor Author

well that wasn't as effective as I had hoped, will revert and then resolve manually

@raddessi
raddessi force-pushed the master.py3-beacons branch from 8e9b7b6 to d585259 Compare April 7, 2020 16:18
Comment thread salt/modules/highstate_doc.py Resolved

@raddessi raddessi left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

one more possible change

@raddessi
raddessi requested a review from DmitryKuzmenko April 15, 2020 20:34
@sagetherage sagetherage removed the v3000.1 vulnerable version label Apr 20, 2020
@raddessi

Copy link
Copy Markdown
Contributor Author

@DmitryKuzmenko how does this look now?

@DmitryKuzmenko DmitryKuzmenko left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm very sorry but here's another one bunch of change requests.

Comment thread salt/beacons/napalm_beacon.py Resolved
Comment thread salt/beacons/napalm_beacon.py Resolved
Comment thread salt/modules/bamboohr.py Resolved
Comment thread salt/modules/bamboohr.py Resolved
Comment thread salt/modules/bamboohr.py Resolved
Comment thread salt/modules/capirca_acl.py Resolved
Comment thread salt/modules/highstate_doc.py Resolved
Comment thread salt/modules/highstate_doc.py Resolved
Comment thread salt/modules/postgres.py Resolved
@bryceml

bryceml commented Apr 27, 2020

Copy link
Copy Markdown
Contributor

re-run all full

@raddessi

Copy link
Copy Markdown
Contributor Author

No need to apologize, the comments look good. I'll try to get this up to date tomorrow. Thanks!

@raddessi

Copy link
Copy Markdown
Contributor Author

Good call, I completely missed one of the loops before. Latest requested changes should be in now @DmitryKuzmenko

@DmitryKuzmenko

Copy link
Copy Markdown
Contributor

Perfect! Thank you!

@dwoz

dwoz commented May 10, 2020

Copy link
Copy Markdown
Contributor

Has anyone validated there is test coverage for the methods changing in this PR?

@raddessi

Copy link
Copy Markdown
Contributor Author

@dwoz not yet. Last I spoke with @DmitryKuzmenko we were both going to try to get that done so this could get in. I have not had any spare time yet unfortunately.

@sagetherage sagetherage added the ZRelease-Sodium retired label label May 12, 2020
@dwoz dwoz added the needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases label May 12, 2020
@dwoz

dwoz commented May 19, 2020

Copy link
Copy Markdown
Contributor

Merging this since @DmitryKuzmenko has no easy way of verifying the test coverage. For the record I'm not a huge fan of the precedence this sets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases ZRelease-Sodium retired label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants