Skip to content

Commit c9f8401

Browse files
Daniel Machjrohel
authored andcommitted
[transaction] Fix 'TransactionItem not found for key' error.
Upgraded and obsoleted packages weren't properly identified in the transaction processing. That resulted in skipping inserting some NEVRAs into the history database and crash. Resolves: rhbz#1601877
1 parent 1ad97e3 commit c9f8401

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

dnf/base.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ def _goal2transaction(self, goal):
708708
for pkg in goal.list_installs():
709709
self._ds_callback.pkg_added(pkg, 'i')
710710
obs = goal.obsoleted_by_package(pkg)
711+
# skip obsoleted packages that are not part of all_obsoleted
712+
# they are handled as upgrades/downgrades
713+
obs = [i for i in obs if i in all_obsoleted]
711714

712715
# TODO: move to libdnf: getBestReason
713716
reason = goal.get_reason(pkg)
@@ -727,17 +730,28 @@ def _goal2transaction(self, goal):
727730
cb = lambda pkg: self._ds_callback.pkg_added(pkg, 'od')
728731
dnf.util.mapall(cb, obs)
729732
for pkg in goal.list_upgrades():
730-
group_fn = functools.partial(operator.contains, all_obsoleted)
731-
obs, upgraded = dnf.util.group_by_filter(
732-
group_fn, goal.obsoleted_by_package(pkg))
733+
obs = goal.obsoleted_by_package(pkg)
734+
upgraded = None
735+
for i in obs:
736+
# try to find a package with matching name as the upgrade
737+
if i.name == pkg.name:
738+
upgraded = i
739+
break
740+
if upgraded is None:
741+
# no matching name -> pick the first one
742+
upgraded = obs.pop(0)
743+
else:
744+
obs.remove(upgraded)
745+
# skip obsoleted packages that are not part of all_obsoleted
746+
# they are handled as upgrades/downgrades
747+
obs = [i for i in obs if i in all_obsoleted]
733748
cb = lambda pkg: self._ds_callback.pkg_added(pkg, 'od')
734749
dnf.util.mapall(cb, obs)
735750
if pkg in self._get_installonly_query():
736751
ts.add_install(pkg, obs)
737752
else:
738-
ts.add_upgrade(pkg, upgraded[0], obs)
739-
cb = lambda pkg: self._ds_callback.pkg_added(pkg, 'ud')
740-
dnf.util.mapall(cb, upgraded)
753+
ts.add_upgrade(pkg, upgraded, obs)
754+
self._ds_callback.pkg_added(upgraded, 'ud')
741755
self._ds_callback.pkg_added(pkg, 'u')
742756
for pkg in goal.list_erasures():
743757
self._ds_callback.pkg_added(pkg, 'e')

0 commit comments

Comments
 (0)