20.04 -> 22.04 upgrade with KDE frontend crashes due to "'str' object has no attribute 'toUtf8'"

Bug #2020414 reported by Matteo Italia
This bug affects 1 person
Affects Status Importance Assigned to Milestone
update-manager (Ubuntu)

Bug Description

Kubuntu 20.04 being upgraded to 22.04 through the KDE frontend of ubuntu-release-upgrader; I may have pressed a key in the terminal view (I had the focus on the wrong window), and the upgrader crashed (and from there it was the usual mess of trying to recover from a broken upgrade; not a fun night).

Now, the usual lesson that keeps true through the years here is that the only sane upgrade path is through console-based `do-release-upgrade`, and all the GUI wrappers for TUI stuff are generally broken; still, looking at the logs:

2023-05-22 22:04:26,219 ERROR not handled exception in KDE frontend:
Traceback (most recent call last):

  File "/tmp/ubuntu-release-upgrader-p9xz8prn/DistUpgrade/DistUpgradeViewKDE.py", line 232, in keyPressEvent
    os.write(self.installProgress.master_fd, ev.text().toUtf8())

AttributeError: 'str' object has no attribute 'toUtf8'

2023-05-22 22:04:26,220 DEBUG running apport_crash()

(I don't think apport managed to really do anything meaningful, as the system was in shambles being updated and pretty much no "complex" application was even able to start due to broken dependencies, including `do-release-upgrade`)

Having worked on porting a number of Python2/PyQt4 applications to Python3/PyQt4 myself, the problem here is a classic one (and one of the reasons why I will no longer invest time in writing anything that should last through the years in Python): this is code that comes from PyQt4/SIP API v1, where Qt classes returned `QString` values like in C++; in SIP API v2 (which was the default with PyQt 5) `QString` was no longer wrapped, and all methods that used to return `QString` now just returned Python `str` objects, which do not have a `toUtf8` method.

A fix that "does the same thing as before" here is to just change

        # now sent the key event to the termianl as utf-8
        os.write(self.installProgress.master_fd, ev.text().toUtf8())


        # now sent the key event to the terminal as utf-8
        os.write(self.installProgress.master_fd, ev.text().encode('utf-8'))
(fixing the comment while we are at it)

To be pedantic, in theory the "right thing" here would be to encode the `str` according to the locale of the process that is running inside the pty, although I'd be afraid of this breaking due to `UnicodeEncodeError: 'ascii' codec can't encode character 'whatever' in position 0: ordinal not in range(128)` if the upgrader is run in some environment where the locale is not set correctly and the user happens to press a non-ASCII key on the keyboard. Besides, I don't even know if it's even supported anymore to run this stuff in a non-UTF-8 environment.

tags: added: dist-upgrade
tags: added: focal jammy
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.