Bug 982071

Summary: Python exception when selecting "install local driver": 'int' object has no attribute 'has_key' [PROPOSED FIX INCLUDED]
Product: [Fedora] Fedora Reporter: Johannes Goller <jogojapan>
Component: system-config-printerAssignee: Tim Waugh <twaugh>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 19CC: jogojapan, jpopelka, twaugh
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: system-config-printer-1.4.5-1.fc20 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-07-10 00:23:58 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Johannes Goller 2013-07-08 05:17:24 UTC
Description of problem:

When running system-config-printer (as root) to install a printer, I am unable to select a local printer driver (PPD): As soon as I click on the "local driver" in the "new printer" dialogue, the program stops working. On STDERR I get a Python exception (details below).


Version-Release number of selected component (if applicable):
system-config-printer 1.4.1_7.fc19

How reproducible: Always

Steps to Reproduce:
1. Run `sudo system-config-printer`
2. Select a printer for which no pre-packaged driver is available
3. Wait until the automated driver search has completed (not finding any driver); do not cancel the search procedure even if it takes 1 minute
4. Select "local driver"

Actual results:
A Python exception thrown on STDERR:

Traceback (most recent call last):
  File "/usr/share/system-config-printer/newprinter.py", line 892, in on_btnNPForward_clicked
    self.nextNPTab()
  File "/usr/share/system-config-printer/newprinter.py", line 1110, in nextNPTab
    if driver != None and driver.has_key ('packages'):
AttributeError: 'int' object has no attribute 'has_key'


Expected results:
The dialogue to continue.

Additional info:
As reported by the Python exception, the problem is caused by this line (line no. 1110) in newprinter.py:

if driver != None and driver.has_key ('packages'):


The reason is that `driver` is not actually `None`, but the integer `0`. I was able to fix the problem by replacing that line with the following

if driver is not None and driver != 0 and driver.has_key ('packages'):

With this in place, the dialogue continues and I am able to install the printer.

Comment 1 Johannes Goller 2013-07-08 05:26:08 UTC
Looking at the current version of the code (master branch), the line I mentioned seems to correspond to line 1125:

https://git.fedorahosted.org/cgit/system-config-printer.git/tree/newprinter.py#n1125

There are other lines in this code that compare `driver` (returned from `model.get_value()` to `None`. I suspect they all need to be prepared for the possibility of a value of `0` instead of `None`.

Comment 2 Jiri Popelka 2013-07-10 14:11:43 UTC
(In reply to Johannes Goller from comment #0)
> 4. Select "local driver"
I can't find any "local driver". I see only:
 * Select printer from database
 * Provide PPD file
 * Search for a printer driver to download

The affected code seem to handle the last case but I can't reproduce it.

> if driver is not None and driver != 0 and driver.has_key ('packages'):

nice, thanks, but we need to know how/why the 0 got there, it could contain other values, not just 0.

Comment 3 Johannes Goller 2013-07-10 14:28:01 UTC
>> 4. Select "local driver"
> I can't find any "local driver". I see only:
>  * Select printer from database
>  * Provide PPD file
>  * Search for a printer driver to download

I am sorry. I was looking at the Japanese version and made assumptions about the English original... It's the "provide a PPD file" option, then.

> nice, thanks, but we need to know how/why the 0 got there, it could contain other values, not just 0.

Sure, my fix is very ad-hoc.

Comment 4 Tim Waugh 2014-06-26 16:28:33 UTC
Tracked the cause of this down to commit b21756ca49e22feb3d055be331739707254516a7:

Commit:     Tim Waugh <twaugh>
CommitDate: Fri Nov 9 18:12:12 2012 +0000

    Avoid putting None in models whose columns don't allow it.

I should have checked for comparisons elsewhere in the code, and for some reason I missed this.

Thanks for the patch. I've applied it now.

Comment 5 Fedora Update System 2014-07-04 16:31:44 UTC
system-config-printer-1.4.5-1.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/system-config-printer-1.4.5-1.fc20

Comment 6 Fedora Update System 2014-07-05 14:55:37 UTC
Package system-config-printer-1.4.5-1.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing system-config-printer-1.4.5-1.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-8100/system-config-printer-1.4.5-1.fc20
then log in and leave karma (feedback).

Comment 7 Fedora Update System 2014-07-10 00:23:58 UTC
system-config-printer-1.4.5-1.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.