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
ubuntu-release-upgrader (Ubuntu)
Status tracked in Mantic
Fix Released
Brian Murray

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
affects: update-manager (Ubuntu) → ubuntu-release-upgrader (Ubuntu)
Changed in ubuntu-release-upgrader (Ubuntu):
importance: Undecided → High
status: New → In Progress
assignee: nobody → Brian Murray (brian-murray)
Revision history for this message
Brian Murray (brian-murray) wrote :

I'm sorry your upgrade didn't go well, but thanks for providing a patch!

I've searched Launchpad and the Ubuntu Error Tracker for crashes in keyPressEvent and didn't find any. However, searching the Error Tracker for ubuntu-release-upgrader crashes is rather difficult due to a lot of noise in there.

So this **may** not be worth SRU'ing but let's get it fixed for Mantic++.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ubuntu-release-upgrader - 1:23.10.3

ubuntu-release-upgrader (1:23.10.3) mantic; urgency=medium

  * DistUpgradeViewKDE.py: Fix a crash when writing text on a key press event.
    Thanks Launchpad user Matteo Italia for the fix. (LP: #2020414)
  * Run pre-build.sh: updating mirrors, demotions, and translations.

 -- Brian Murray <email address hidden> Fri, 09 Jun 2023 14:26:34 -0700

Changed in ubuntu-release-upgrader (Ubuntu Mantic):
status: In Progress → Fix Released
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.