Bug 53571 - computerroom/query: IndexError: list index out of range
computerroom/query: IndexError: list index out of range
Status: CLOSED FIXED
Product: UCS@school
Classification: Unclassified
Component: UMC - Computer room
UCS@school 5.0
Other Linux
: P5 normal (vote)
: UCS@school 5.0 v4-errata
Assigned To: Tobias Wenzel
J Leadbetter
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2021-07-13 11:47 CEST by Christian Castens
Modified: 2023-11-16 14:21 CET (History)
4 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2021071221000592, 2021042821000317, 2022012121000637
Bug group (optional): Error handling, External feedback
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Castens univentionstaff 2021-07-13 11:47:37 CEST
Version: 5.0-0 errata44

Error:
Interner Server-Fehler in "computerroom/query".
Request: computerroom/query

Traceback (most recent call last):
  File "%PY3%/univention/management/console/base.py", line 344, in __error_handling
    six.reraise(etype, exc, etraceback)
  File "%PY3%/six.py", line 693, in reraise
    raise value
  File "%PY3%/univention/management/console/base.py", line 247, in execute
    function.__func__(self, request, *args, **kwargs)
  File "%PY3%/ucsschool/lib/school_umc_ldap_connection.py", line 155, in wrapper_func
    return func(*args, **kwargs)
  File "%PY3%/univention/management/console/modules/computerroom/__init__.py", line 534, in query
    result = [computer.dict for computer in self._computerroom.values()]
  File "%PY3%/univention/management/console/modules/computerroom/__init__.py", line 534, in <listcomp>
    result = [computer.dict for computer in self._computerroom.values()]
  File "%PY3%/univention/management/console/modules/computerroom/room_management.py", line 527, in dict
    "mac": self.macAddress,
  File "%PY3%/univention/management/console/modules/computerroom/room_management.py", line 458, in macAddress
    return ip_addresses[0]
IndexError: list index out of range

Role: domaincontroller_master

Errno: 287b3eea0c923797e514e90a9ace4bec
Comment 1 Florian Best univentionstaff 2021-07-13 12:02:11 CEST
Happens when opening the computerroom module and the selected room contains an computer without an IP address.
Comment 2 Florian Best univentionstaff 2021-07-13 12:02:48 CEST
(In reply to Florian Best from comment #1)
> Happens when opening the computerroom module and the selected room contains
> an computer without an IP address.

s/IP/MAC/g
Comment 3 Tobias Wenzel univentionstaff 2021-10-22 15:57:13 CEST
I could only partly reproduce this in 4.4 & 5.0. 

UCS: 4.4-8 errata1044
Installed: cups=2.2.1 samba4=4.10 squid=3.5 ucsschool=4.4 v9



this should be renamed, too:

ip_addresses -> mac_addresses

    @property
    def macAddress(self):
        ip_addresses = self._computer.info.get("mac", [""])
        return ip_addresses[0]
Comment 5 Maximilian Janßen univentionstaff 2021-11-26 11:03:50 CET
reported again:


Version: 4.4-8 errata962 (Blumenthal) - UCS@school 4.4 v9

Error: 
Interner Server-Fehler in "computerroom/query".
Request: computerroom/query

Traceback (most recent call last):
  File "%PY2.7%/univention/management/console/base.py", line 359, in __error_handling
    six.reraise(etype, exc, etraceback)
  File "%PY2.7%/univention/management/console/base.py", line 262, in execute
    function.__func__(self, request, *args, **kwargs)
  File "%PY2.7%/ucsschool/lib/school_umc_ldap_connection.py", line 145, in wrapper_func
    return func(*args, **kwargs)
  File "%PY2.7%/univention/management/console/modules/computerroom/__init__.py", line 544, in query
    result = [computer.dict for computer in self._italc.values()]
  File "%PY2.7%/univention/management/console/modules/computerroom/room_management.py", line 1077, in dict
    "mac": self.macAddress,
  File "%PY2.7%/univention/management/console/modules/computerroom/room_management.py", line 1008, in macAddress
    return ip_addresses[0]
IndexError: list index out of range

Role: domaincontroller_master
Comment 6 Tobias Wenzel univentionstaff 2023-10-26 11:53:24 CEST
Looks like this is the issue:

>>> info = {"mac": []}
>>> info.get("mac")
[]
>>> info.get("mac")[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range


We did the following in macAddress:

mac_addresses = self._computer.info.get("mac", [""])
return mac_addresses[0]


For me it looks like if the mac is not set, we have self._computer.info.get("mac") == [].

Possible solutions:

    @property
    def macAddress(self):
        mac_addresses = self._computer.info.get("mac", None)
        if mac_addresses is None:
            mac_addresses = [""]
        return mac_addresses[0]

or, to have it similar to ip_addresses (,after  self._mac_addresses = self._computer.info.get("mac", [])  # type: List[str] in init):

    @property
    def macAddress(self):
        return self._mac_addresses[0] if self._mac_addresses else ""
Comment 7 Tobias Wenzel univentionstaff 2023-10-26 12:28:32 CEST
florian suggested the following one liner:

     @property
     def macAddress(self):
-        ip_addresses = self._computer.info.get("mac", [""])
-        return ip_addresses[0]
+        return (self._computer.info.get("mac") or [""])[0]
Comment 8 Tobias Wenzel univentionstaff 2023-11-06 10:06:07 CET
If a computer does not have an MAC address, it will still be displayed in the computer room and no error is thrown.

With this issue, also https://forge.univention.org/bugzilla/show_bug.cgi?id=53624 
is fixed.

Merged & built with

Package: ucs-school-umc-computerroom
Version: 12.0.14
Branch: ucs_5.0-0
Scope: ucs-school-5.0

Package: ucs-test-ucsschool
Version: 7.3.148
Branch: ucs_5.0-0
Scope: ucs-school-5.0
Comment 10 J Leadbetter univentionstaff 2023-11-16 14:21:08 CET
Errata updates for UCS@school 5.0 v4 have been released.

https://docs.software-univention.de/ucsschool-changelog/5.0v4/en/changelog.html
https://docs.software-univention.de/ucsschool-changelog/5.0v4/de/changelog.html

If this error occurs again, please clone this bug.