Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: query of subkey of dict that is in a subset of assets results in TypeError #697

Open
aqw opened this issue Oct 24, 2024 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@aqw
Copy link
Collaborator

aqw commented Oct 24, 2024

Like #696, this is easiest to explore in our inventory repo.

Some assets contain the following structure:

connectors:
  mDP: 1
  DP: 2 # 1 x out w/ MST
  HDMI: 1
  USB-A: 4
  USB-B: 1
  3_5: 1
  DVI: 1

However, do not have the connectors key.

When addressing the connectors key directly, all is well:

❱ onyo get --keys connectors
 ──────────── 
  connectors  
 ──────────── 
  <dict>      
  <unset>     
  <dict>      
...
  <dict>      
  <unset>     
 ──────────── 

However, addressing a subkey (valid or invalid) fails:

❱ onyo get --keys connectors.DVI
ERROR: 'connectors' is not a dictionary.

Traceback shows TypeError:

❱ onyo --debug get --keys connectors.DVI
...
ERROR: 'connectors' is not a dictionary.
DEBUG:onyo:Traceback (most recent call last):
  File "/home/aqw/git/inm7/onyo/onyo/lib/utils.py", line 92, in __getitem__
    return effective_dict[parts[-1]]
           ~~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/aqw/git/inm7/onyo/onyo/main.py", line 543, in main
    args.run(args)
  File "/home/aqw/git/inm7/onyo/onyo/cli/get.py", line 187, in get
    results = onyo_get(inventory=inventory,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/aqw/git/inm7/onyo/onyo/lib/commands.py", line 83, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/aqw/git/inm7/onyo/onyo/lib/commands.py", line 537, in onyo_get
    results = [{k: r[k] if k in r and r[k] not in [None, ""] else UNSET_VALUE
                           ^^^^^^
  File "/home/aqw/git/inm7/onyo/onyo/lib/utils.py", line 136, in __contains__
    self.__getitem__(key)
  File "/home/aqw/git/inm7/onyo/onyo/lib/utils.py", line 96, in __getitem__
    raise TypeError(f"'{'.'.join(parts[:-1])}' is not a dictionary.") from e
TypeError: 'connectors' is not a dictionary.
@aqw aqw added the bug Something isn't working label Oct 24, 2024
@bpoldrack bpoldrack self-assigned this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants