Commit 9100ea9
committed
Fix unordered dict bug in to_dict()
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
{"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_refs1 parent 3882277 commit 9100ea9
2 files changed
Lines changed: 14 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
| 26 | + | |
| 27 | + | |
21 | 28 | | |
22 | 29 | | |
23 | 30 | | |
| |||
57 | 64 | | |
58 | 65 | | |
59 | 66 | | |
60 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
| |||
68 | 79 | | |
69 | 80 | | |
70 | 81 | | |
| 82 | + | |
71 | 83 | | |
72 | 84 | | |
73 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
0 commit comments