utils: distutils.version.LooseVersion comparison fails in bookworm
I saw this issue when testing my https://salsa.debian.org/jvalleroy/freedombox/-/tree/firewall-1.2 change, after a dist-upgrade from bullseye to bookworm.
(For context, this is the issue I initially tried to fix in !2284 (closed).)
p 03 16:37:48 freedombox /usr/bin/plinth[1625]: Packages that need conffile upgrades: {'firewalld': {'current_version': '0.9.3-2', 'new_version': '1.2.0-1', 'modified_conffiles': ['/etc/firewalld/firewalld.conf']}}
Sep 03 16:37:48 freedombox /usr/bin/plinth[1625]: Apps needing conffile upgrades: Firewall
Sep 03 16:37:48 freedombox /usr/bin/plinth[1625]: Force upgrading app: Firewall
Sep 03 16:37:48 freedombox /usr/bin/plinth[1625]: Operation: firewall: Updating app packages: added
Sep 03 16:37:48 freedombox /usr/bin/plinth[1625]: Operation: firewall: Updating app packages: running
Sep 03 16:37:48 freedombox /usr/bin/plinth[1625]: Error: Operation: firewall: Updating app packages, '<' not supported between instances of 'int' and 'str'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/plinth/operation.py", line 61, in _catch_thread_errors
self.return_value = self.target(*self.args, **self.kwargs)
File "/usr/lib/python3/dist-packages/plinth/modules/firewall/__init__.py", line 91, in force_upgrade
if Version(package['new_version']) > Version('1.2~'):
File "/usr/lib/python3.10/distutils/version.py", line 64, in __gt__
c = self._cmp(other)
File "/usr/lib/python3.10/distutils/version.py", line 341, in _cmp
if self.version < other.version:
TypeError: '<' not supported between instances of 'int' and 'str'
Sep 03 16:37:48 freedombox /usr/bin/plinth[1625]: Error running force upgrade: '<' not supported between instances of 'int' and 'str'
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/plinth/setup.py", line 435, in _attempt_upgrade
if self._run_force_upgrade_as_operation(app, packages):
File "/usr/lib/python3/dist-packages/plinth/setup.py", line 456, in _run_force_upgrade_as_operation
return operation.join() # Wait for completion, raise Exception
File "/usr/lib/python3/dist-packages/plinth/operation.py", line 87, in join
raise self.exception
File "/usr/lib/python3/dist-packages/plinth/operation.py", line 61, in _catch_thread_errors
self.return_value = self.target(*self.args, **self.kwargs)
File "/usr/lib/python3/dist-packages/plinth/modules/firewall/__init__.py", line 91, in force_upgrade
if Version(package['new_version']) > Version('1.2~'):
File "/usr/lib/python3.10/distutils/version.py", line 64, in __gt__
c = self._cmp(other)
File "/usr/lib/python3.10/distutils/version.py", line 341, in _cmp
if self.version < other.version:
TypeError: '<' not supported between instances of 'int' and 'str'
Sep 03 16:37:48 freedombox /usr/bin/plinth[1625]: Cannot perform upgrade now: Some apps failed to force upgrade.
Searching for the error lead me to https://github.com/pypa/distutils/issues/22, which mentions that distutils.version is deprecated.