Skip to content

Commit

Permalink
[configlet] Python3 compatible syntax for extracting a key from the d…
Browse files Browse the repository at this point in the history
…ict (sonic-net#1721)

Signed-off-by: Neetha John <[email protected]>

Syntax error seen while trying to apply a configlet
Traceback (most recent call last):
File "/usr/local/bin/configlet", line 212, in
main()
File "/usr/local/bin/configlet", line 205, in main
process_entry (do_update, i)
File "/usr/local/bin/configlet", line 175, in process_entry
do_operate(op_upd, t, (), data[t])
File "/usr/local/bin/configlet", line 162, in do_operate
if type(lst[lst.keys()[0]]) == dict:
TypeError: 'dict_keys' object is not subscriptable

What I did
Use next(iter()) to derive a key from the dict. This is both python2 and python3 compatible

How to verify it
Tried applying the json file below using the command 'configlet -j test.json -d'. Configlet was applied successfully. No errors were seen
[
{
"ACL_TABLE": {
"EVERFLOW": {},
"EVERFLOWV6": {}
}
}
]
  • Loading branch information
neethajohn authored Jul 21, 2021
1 parent 9b7c58b commit acb5d84
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/configlet
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def do_delete(t, k, lst):

def do_operate(op_upd, t, k, lst):
if lst:
if type(lst[lst.keys()[0]]) == dict:
if type(lst[next(iter(lst))]) == dict:
for i in lst:
do_operate(op_upd, t, k+(i,), lst[i])
return
Expand Down

0 comments on commit acb5d84

Please sign in to comment.