[Bug 2020414] Re: 20.04 -> 22.04 upgrade with KDE frontend crashes due to "'str' object has no attribute 'toUtf8'"

Brian Murray 2020414 at bugs.launchpad.net
Fri Jun 9 21:16:06 UTC 2023


** Changed in: ubuntu-release-upgrader (Ubuntu)
   Importance: Undecided => High

** Changed in: ubuntu-release-upgrader (Ubuntu)
       Status: New => In Progress

** Changed in: ubuntu-release-upgrader (Ubuntu)
     Assignee: (unassigned) => Brian Murray (brian-murray)

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to ubuntu-release-upgrader in
Ubuntu.
https://bugs.launchpad.net/bugs/2020414

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

Status in ubuntu-release-upgrader package in Ubuntu:
  In Progress

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())
  ```

  to

  ```
          # 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.

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/2020414/+subscriptions




More information about the foundations-bugs mailing list