Blob Blame History Raw
From d76d54277bc51398f7aa20b3dce0863e3520810b Mon Sep 17 00:00:00 2001
From: Eric Garver <eric@garver.life>
Date: Wed, 29 Jul 2020 15:18:38 -0400
Subject: [PATCH 43/45] fix(LastUpdatedOrderedDict): __getitem__(): fetch from
 list if int

If the LastUpdatedOrderedDict contains a boolean key, e.g.

    myLastUpdatedOrderedDict = LastUpdatedOrderedDict()
    myLastUpdatedOrderedDic[True] = "true"

then

    myLastUpdatedOrderedDic[1]

yields "true". As such, using the LastUpdatedOrderedDict as an iterable
e.g.

    for foo in myLastUpdatedOrderedDict:
        ...

would mean that the for loop tries integer indexes 0 (returns key True),
and then 1 (also returns key True). This caused duplicate walks of a key
True if it was the first key in the LastUpdatedOrderedDict.

This occurs because

    >>> True == 1
    True
    >>> False == 0
    True

(cherry picked from commit 55754b65be6eaa697382992679e6673346e39f78)
(cherry picked from commit 1561dbc6c2b8f8f7f27b89810a8dda9b869b1923)
---
 src/firewall/fw_types.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/firewall/fw_types.py b/src/firewall/fw_types.py
index 07c69c61702f..3d90c1812aec 100644
--- a/src/firewall/fw_types.py
+++ b/src/firewall/fw_types.py
@@ -54,10 +54,10 @@ class LastUpdatedOrderedDict(object):
         self._dict[key] = value
 
     def __getitem__(self, key):
-        if key in self._dict:
-            return self._dict[key]
-        else:
+        if type(key) == int:
             return self._list[key]
+        else:
+            return self._dict[key]
 
     def __len__(self):
         return len(self._list)
-- 
2.27.0