Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.

Bug 1514418

Summary: dnf --security check-update fails TypeError: 'NoneType' object is not iterable
Product: [Fedora] Fedora Reporter: Martin Schuhmacher <bugzilla>
Component: dnfAssignee: Marek Blaha <mblaha>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 27CC: dmach, jmracek, mblaha, packaging-team-maint, rpm-software-management, vmukhame
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: dnf-4.0.4 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-11-22 18:25:59 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:

Description Martin Schuhmacher 2017-11-17 11:11:37 UTC
rpm -qi dnf
Name        : dnf
Version     : 2.7.5
Release     : 1.fc27

dnf --security check-update 
Last metadata expiration check: 0:15:22 ago on Thu 16 Nov 2017 04:27:43 PM CET.
Traceback (most recent call last):
  File "/usr/bin/dnf", line 58, in <module>
    main.user_main(sys.argv[1:], exit_code=True)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 179, in user_main
    errcode = main(args)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 64, in main
    return _main(base, args, cli_class, option_parser_class)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 99, in _main
    return cli_run(cli, base)
  File "/usr/lib/python3.6/site-packages/dnf/cli/main.py", line 115, in cli_run
    cli.run()
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 1011, in run
    return self.command.run()
  File "/usr/lib/python3.6/site-packages/dnf/cli/commands/__init__.py", line 274, in run
    found = self.base.check_updates(self.opts.packages, print_=True)
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 289, in check_updates
    typl = self.returnPkgLists('obsoletes', patterns, reponame=reponame)
  File "/usr/lib/python3.6/site-packages/dnf/cli/cli.py", line 505, in returnPkgLists
    pkgnarrow, patterns, ignore_case=True, reponame=reponame)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 1268, in _do_package_lists
    return list_fn(None)
  File "/usr/lib/python3.6/site-packages/dnf/base.py", line 1399, in _list_pattern
    for new in obsoletes:
TypeError: 'NoneType' object is not iterable


maybe the following patches fix it?
diff -uN base.py.orig base.py
--- base.py.orig	2017-11-17 12:07:13.989090222 +0100
+++ base.py	2017-11-17 11:54:24.157932734 +0100
@@ -1396,11 +1396,12 @@
             # reduce a query to security upgrades if they are specified
             obsoletes = self._merge_update_filters(obsoletes, warning=False)
             obsoletesTuples = []
-            for new in obsoletes:
-                obsoleted_reldeps = new.obsoletes
-                obsoletesTuples.extend(
-                    [(new, old) for old in
-                     inst.filter(provides=obsoleted_reldeps)])
+            if obsoletes is not None:
+                for new in obsoletes:
+                    obsoleted_reldeps = new.obsoletes
+                    obsoletesTuples.extend(
+                        [(new, old) for old in
+                         inst.filter(provides=obsoleted_reldeps)])
 
         # packages recently added to the repositories
         elif pkgnarrow == 'recent':

and
diff -uN cli.py.orig /usr/lib/python3.6/site-packages/dnf/cli/cli.py 
--- cli.py.orig	2017-11-17 12:10:18.734320533 +0100
+++ /usr/lib/python3.6/site-packages/dnf/cli/cli.py	2017-11-17 11:54:09.222654717 +0100
@@ -95,7 +95,7 @@
                 ypl.updates, ypl.recent):
         for pkg in lst:
             _add_pkg_simple_list_lens(data, pkg)
-    if len(ypl.obsoletes) > 0:
+    if (ypl.obsoletes is not None) and (len(ypl.obsoletes) > 0):
         for (npkg, opkg) in ypl.obsoletesTuples:
             _add_pkg_simple_list_lens(data, npkg)
             _add_pkg_simple_list_lens(data, opkg, indent=" " * 4)
@@ -307,7 +307,7 @@
                 self.output.listPkgs(ypl.updates, '', outputType='list',
                               highlight_na=local_pkgs, columns=columns,
                               highlight_modes={'=' : cul, 'not in' : cur})
-            if len(ypl.obsoletes) > 0:
+            if (ypl.obsoletes is not None) and (len(ypl.obsoletes) > 0):
                 print(_('Obsoleting Packages'))
                 # The tuple is (newPkg, oldPkg) ... so sort by new
                 for obtup in sorted(ypl.obsoletesTuples,

Comment 1 Daniel Mach 2017-11-29 12:11:39 UTC
Suggested change:
-            if len(ypl.obsoletes) > 0:
+            if ypl.obsoletes:

Comment 2 Marek Blaha 2017-12-04 09:57:56 UTC
Hi, I've created another patch (which hopefully fixes root of this bug). If you are still able to reproduce this bug, here is link to pach:

https://github.com/rpm-software-management/dnf/pull/995

Thanks for reporting the bug.