Fix unordered dict bug in to_dict()#689
Merged
caphrim007 merged 1 commit intoF5Networks:developmentfrom Sep 14, 2016
Merged
Conversation
Issues: Fixes F5Networks#687 Problem: On python3 (and also I presume on python2) the test_two_refs test in test_mixins.py will fail because the returned value is {"x": [TraversalRecord, "z"], "z": [1, "a"]} instead of the expected value {"x": [1, "a"], "z": ["TraversalRecord", "x"]} Analysis: I tracked this down to the `_traverse_dict()` method where it iterates over the values of the `instance_dict` variable. The problem is that because dictionaries are unordered, the first value that is iterated upon will sometimes return "z" first instead of "x". This causes the result to become "turned around" and the test to fail. I never saw this crop up on python 2, but it crops up regularly on python 3. The fix I applied is to cast the unordered dict in `_traverse_dict` into an OrderedDict. Doing this makes the values of that variable always known, so-to-speak, because they have a defined order. Therefore the tests will pass as expected. Tests: * f5/bigip/test/test_mixins.py::test_to_refs
306e741 to
9100ea9
Compare
Contributor
Author
Contributor
|
Nice job @caphrim007 !! Thanks. I'm +1 to merge this... I'm OK with a new pip dependency for <= 2.6. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues:
Fixes #687
Problem:
On python3 (and also I presume on python2) the test_two_refs test in
test_mixins.py will fail because the returned value is
instead of the expected value
Analysis:
I tracked this down to the
_traverse_dict()method where it iteratesover the values of the
instance_dictvariable. The problem is thatbecause dictionaries are unordered, the first value that is iterated
upon will sometimes return "z" first instead of "x".
This causes the result to become "turned around" and the test to fail.
I never saw this crop up on python 2, but it crops up regularly on
python 3. The fix I applied is to cast the unordered dict in
_traverse_dictinto an OrderedDict. Doing this makes the values of that variable always
known, so-to-speak, because they have a defined order. Therefore the
tests will pass as expected.
Tests: