itkdb.models.component.Component.walk() broken if component child is None
>>> import itkdb
>>> c = itkdb.Client()
>>> comp = c.get('getComponent', json={'component': '20UPGM22601020'})
>>> pprint(comp['children'])
[
│ {
│ │ 'id': '6e8914c8c26c06b083b53a9444de193a',
│ │ 'order': 0,
│ │ 'state': 'ready',
│ │ 'timestamp': '2023-05-24T13:55:36.464Z',
│ │ 'identity': '6436-7637-1',
│ │ 'componentType': {
│ │ │ 'id': '5e46bf0698b10e000ad6ffef',
│ │ │ 'code': 'MODULE_CARRIER',
│ │ │ 'name': 'Module carrier',
│ │ │ 'category': 'reusable'
│ │ },
│ │ 'type': {'code': 'CARRIER', 'name': 'CARRIER'},
│ │ 'component': None
│ },
which crashes as the child's child["component"]["id"]
doesn't work since child["component"] is None
.
│
│ /Users/oide/Library/Python/3.12/lib/python/site-packages/itkdb/models/component.py:45 in walk │
│ │
│ 42 │ │ │ data = child │
│ 43 │ │ │ with suppress(BadRequest, KeyError): │
│ 44 │ │ │ │ data = self._client.get( # type: ignore[no-untyped-call] │
│ ❱ 45 │ │ │ │ │ "getComponent", json={"component": child["component"]["id"]} │
│ 46 │ │ │ │ ) │
│ 47 │ │ │ │
│ 48 │ │ │ child_component = Component(self._client, data) │
│ │
│ ╭────────────────────────────────────── locals ───────────────────────────────────────╮ │
│ │ child = { │ │
│ │ │ 'id': '6e8914c8c26c06b083b53a9444de193a', │ │
│ │ │ 'order': 0, │ │
│ │ │ 'state': 'ready', │ │
│ │ │ 'timestamp': '2023-05-24T13:55:36.464Z', │ │
│ │ │ 'identity': '6436-7637-1', │ │
│ │ │ 'componentType': { │ │
│ │ │ │ 'id': '5e46bf0698b10e000ad6ffef', │ │
│ │ │ │ 'code': 'MODULE_CARRIER', │ │
│ │ │ │ 'name': 'Module carrier', │ │
│ │ │ │ 'category': 'reusable' │ │
│ │ │ }, │ │
│ │ │ 'type': {'code': 'CARRIER', 'name': 'CARRIER'}, │ │
│ │ │ 'component': None │ │
│ │ } │ │
│ │ data = { │ │
│ │ │ 'id': '6e8914c8c26c06b083b53a9444de193a', │ │
│ │ │ 'order': 0, │ │
│ │ │ 'state': 'ready', │ │
│ │ │ 'timestamp': '2023-05-24T13:55:36.464Z', │ │
│ │ │ 'identity': '6436-7637-1', │ │
│ │ │ 'componentType': { │ │
│ │ │ │ 'id': '5e46bf0698b10e000ad6ffef', │ │
│ │ │ │ 'code': 'MODULE_CARRIER', │ │
│ │ │ │ 'name': 'Module carrier', │ │
│ │ │ │ 'category': 'reusable' │ │
│ │ │ }, │ │
│ │ │ 'type': {'code': 'CARRIER', 'name': 'CARRIER'}, │ │
│ │ │ 'component': None │ │
│ │ } │ │
│ │ recurse = True │ │
│ │ self = <itkdb.models.component.Component object '20UPGM22601020' at 0x11f035a00> │ │
│ ╰─────────────────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: 'NoneType' object is not subscriptable