Comment 0 for bug 1880275

Revision history for this message
M. Vefa Bicakci (mvb) wrote :

Hello,

I discovered on a Fedora 31 installation that the hp-toolbox uses a deprecated Qt API function for QGridLayout named setMargin(). This causes an exception to be thrown by Qt when hp-toolbox is attempting to authenticate the user by asking for the user's username and password. Due to the exception, the password dialog creation fails, and hp-toolbox enters and infinite loop with the CUPS daemon, which spams the system journal...

Here is the problematic code in question:

=== /usr/share/hplip/ui5/devmgr5.py ===
class PasswordDialog(QDialog):
    def __init__(self, prompt, parent=None, name=None, modal=0, fl=0):
        QDialog.__init__(self, parent)
        self.prompt = prompt

        Layout= QGridLayout(self)
        Layout.setMargin(11)

The setMargin API function has been deprecated according to "https://doc.qt.io/qt-5/qlayout-obsolete.html". This causes an exception to be thrown by Qt.

Here are the log messages in the system journal indicating the infinite loop:

May 23 08:35:48 cupsd[12123]: [Client 3742370] Empty Basic password.
May 23 08:35:48 cupsd[12123]: REQUEST localhost - - "POST /admin/ HTTP/1.1" 401 121 CUPS-Set-Default successful-ok
May 23 08:35:48 cupsd[12123]: [Client 3742373] Empty Basic password.
May 23 08:35:48 cupsd[12123]: REQUEST localhost - - "POST /admin/ HTTP/1.1" 401 121 CUPS-Set-Default successful-ok
May 23 08:35:48 cupsd[12123]: [Client 3742376] Empty Basic password.
May 23 08:35:48 cupsd[12123]: REQUEST localhost - - "POST /admin/ HTTP/1.1" 401 121 CUPS-Set-Default successful-ok

When I modify the code to catch the exception in showPasswordUI as follows:

=== /usr/share/hplip/ui5/devmgr5.py ===
def showPasswordUI(prompt):
    try:
        dlg = PasswordDialog(prompt, None)

        if dlg.exec_() == QDialog.Accepted:
            return (dlg.getUsername(), dlg.getPassword())

    except Exception as e:
        log.error("Exception in password dialog: {}".format(e))
        log.error("Traceback: {}".format(traceback.format_exc()))
    finally:
        pass

    return ("", "")

Then, I encounter the following output from hp-toolbox:

error: Exception in password dialog: 'QGridLayout' object has no attribute 'setMargin'
error: Traceback: Traceback (most recent call last):
  File "/usr/share/hplip/ui5/devmgr5.py", line 2306, in showPasswordUI
    dlg = PasswordDialog(prompt, None)
  File "/usr/share/hplip/ui5/devmgr5.py", line 2251, in __init__
    Layout.setMargin(11)
AttributeError: 'QGridLayout' object has no attribute 'setMargin'

error: Start/Stop printer queue operation fails. Error : client-error-not-authenticated

All this to say, would it be possible to update the code so that the setMargin(11) call is replaced with the non-obsolete API call setContentsMargins(11, 11, 11, 11) to avoid this error?

In addition, would it be possible to catch exceptions in showPasswordUI so that similar problems would be easier to debug in the future?

Thanks!