From cedb29d0647a5499638fe2137d5b9470ac3cc6e8 Mon Sep 17 00:00:00 2001 From: toeknee2120 <48630756+toeknee2120@users.noreply.github.com> Date: Mon, 29 Jun 2026 10:07:06 -0500 Subject: [PATCH 1/3] Update _match_keys() Reorder if/else block to check if dic[dic_key] is iterable before trying to use the in keyword on it. --- pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/interface.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/interface.py b/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/interface.py index d208b8df9..8afeed808 100644 --- a/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/interface.py +++ b/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/interface.py @@ -464,11 +464,11 @@ def _match_keys(self, dic, match): if isinstance(dic, dict): for key, value in match.items(): for dic_key in dic: - if key in dic[dic_key] and dic[dic_key][key] == value: + if not isinstance(dic[dic_key], dict): + pass + elif key in dic[dic_key] and dic[dic_key][key] == value: self.ret_dict.update(dic) break - elif not isinstance(dic[dic_key], dict): - pass else: self._match_keys(dic=dic[dic_key], match=match) return(self.ret_dict) From d6c3ddb2bfbc89f87b65c24ffaf3108e76951009 Mon Sep 17 00:00:00 2001 From: toeknee2120 <48630756+toeknee2120@users.noreply.github.com> Date: Sat, 4 Jul 2026 16:16:34 -0500 Subject: [PATCH 2/3] Refactor key matching logic in rev1/interface.py --- .../src/genie/libs/ops/interface/nxos/rev1/interface.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/rev1/interface.py b/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/rev1/interface.py index d226f6612..fe81c32f0 100644 --- a/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/rev1/interface.py +++ b/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/rev1/interface.py @@ -485,11 +485,11 @@ def _match_keys(self, dic, match): if isinstance(dic, dict): for key, value in match.items(): for dic_key in dic: - if key in dic[dic_key] and dic[dic_key][key] == value: + if not isinstance(dic[dic_key], dict): + pass + elif key in dic[dic_key] and dic[dic_key][key] == value: self.ret_dict.update(dic) break - elif not isinstance(dic[dic_key], dict): - pass else: self._match_keys(dic=dic[dic_key], match=match) - return(self.ret_dict) \ No newline at end of file + return(self.ret_dict) From 046ff787b7a17856255b03ec42916da81e59dc7d Mon Sep 17 00:00:00 2001 From: tony Date: Sat, 4 Jul 2026 16:55:04 -0500 Subject: [PATCH 3/3] Add unittest --- .../ops/interface/nxos/tests/test_interface.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/tests/test_interface.py b/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/tests/test_interface.py index 0cc116b14..9c839a83d 100644 --- a/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/tests/test_interface.py +++ b/pkgs/ops-pkg/src/genie/libs/ops/interface/nxos/tests/test_interface.py @@ -133,6 +133,22 @@ def test_incomplete_output(self): # Verify Ops was created successfully self.assertDictEqual(intf.info, expect_dict) + def test_match_keys_ignores_scalar_values(self): + intf = Interface(device=self.device) + intf.ret_dict = {} +g + routing_dict = { + "route1": { + "interface": "Ethernet2/1", + "tag": 10, + }, + "scalar": "not-a-dict", + } + + intf._match_keys(dic=routing_dict, match={"interface": "Ethernet2/1"}) + + self.assertEqual(intf.ret_dict, routing_dict) + def test_brief_output(self): self.maxDiff = None intf = InterfaceRev1(device=self.device)