Skip to content

Conversation

Bastian-Krause
Copy link
Member

Description
It is possible to create matches as:

$ export LG_PLACE=myplace
$ labgrid-client create
$ labgrid-client add-match myexporter/mygroup/mycls
$ labgrid-client add-named-match myexporter/mygroup/mycls/myname myrename

In this scenario, labgrid-client show throws an exception:

$ labgrid-client show
Place 'myplace':
  matches:
Traceback (most recent call last):
  File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/labgrid/remote/client.py", line 2171, in main
    session.loop.run_until_complete(coro)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/labgrid/remote/client.py", line 500, in print_place
    place.show(level=1)
    ~~~~~~~~~~^^^^^^^^^
  File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/labgrid/remote/common.py", line 280, in show
    for match in sorted(self.matches):
                 ~~~~~~^^^^^^^^^^^^^^
  File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/attr/_make.py", line 1713, in __lt__
    return attrs_to_tuple(self) < attrs_to_tuple(other)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'NoneType'

The problem arises due to ResourceMatch objects being turned into tuples by attrs for ordering, such as:

("myexporter", "mygroup", "mycls", None)
("myexporter", "mygroup", "mycls", "myname")

First, all elements with index 0 are compared, if these elements are equal, elements with index 1 are compared and so forth until an order can be determined. Normally, the comparison does not reach the "name" element of the match.

In the example above, the first three elements are equal, so None and "myname" are compared, which is unsupported and results in the TypeError.

Fix that by removing the ResourceMatch's optional "name" attribute from ordering operations.

Checklist

  • PR has been tested

Fixes #1736

It is possible to create matches as:

  $ export LG_PLACE=myplace
  $ labgrid-client create
  $ labgrid-client add-match myexporter/mygroup/mycls
  $ labgrid-client add-named-match myexporter/mygroup/mycls/myname myrename

In this scenario, `labgrid-client show` throws an exception:

  $ labgrid-client show
  Place 'myplace':
    matches:
  Traceback (most recent call last):
    File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/labgrid/remote/client.py", line 2171, in main
      session.loop.run_until_complete(coro)
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
    File "/usr/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
      return future.result()
             ~~~~~~~~~~~~~^^
    File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/labgrid/remote/client.py", line 500, in print_place
      place.show(level=1)
      ~~~~~~~~~~^^^^^^^^^
    File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/labgrid/remote/common.py", line 280, in show
      for match in sorted(self.matches):
                   ~~~~~~^^^^^^^^^^^^^^
    File "/usr/ptx-venvs/labgrid/lib/python3.13/site-packages/attr/_make.py", line 1713, in __lt__
      return attrs_to_tuple(self) < attrs_to_tuple(other)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  TypeError: '<' not supported between instances of 'str' and 'NoneType'

The problem arises due to ResourceMatch objects being turned into tuples
by attrs for ordering, such as:

  ("myexporter", "mygroup", "mycls", None)
  ("myexporter", "mygroup", "mycls", "myname")

First, all elements with index 0 are compared, if these elements are
equal, elements with index 1 are compared and so forth until an order
can be determined. Normally, the comparison does not reach the "name"
element of the match.

In the example above, the first three elements are equal, so None and
"myname" are compared, which is unsupported and results in the
TypeError.

Fix that by removing the ResourceMatch's optional name attribute from
ordering operations.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.4%. Comparing base (1070d36) to head (39df0ca).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1742   +/-   ##
======================================
  Coverage    45.4%   45.4%           
======================================
  Files         172     172           
  Lines       13503   13503           
======================================
  Hits         6131    6131           
  Misses       7372    7372           
Flag Coverage Δ
3.10 45.4% <100.0%> (ø)
3.11 45.4% <100.0%> (ø)
3.12 45.4% <100.0%> (ø)
3.13 45.3% <100.0%> (ø)
3.9 45.4% <100.0%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

labgrid-client show with bogus resources results in TypeError: '<' not supported between instances of 'str' and 'NoneType'
1 participant