Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2023652

Summary: KeyError after upgrading packages (post-transaction actions)
Product: Red Hat Enterprise Linux 8 Reporter: Imre Jonk <imre>
Component: dnf-plugins-coreAssignee: Jaroslav Mracek <jmracek>
Status: CLOSED ERRATA QA Contact: Eva Mrakova <emrakova>
Severity: low Docs Contact:
Priority: low    
Version: 8.5CC: james.antill, jrohel, mbanas, reynolds
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: dnf-plugins-core-4.0.21-12.el8 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-08 10:53:15 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 Imre Jonk 2021-11-16 09:48:30 UTC
Description of problem:
I noticed this traceback after updating some kernel packages on my RHEL 8.5 servers:

```
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/plugin.py", line 104, in _caller
    getattr(plugin, method)()
  File "/usr/lib/python3.6/site-packages/dnf-plugins/post-transaction-actions.py", line 134, in transaction
    pkgs = [tsi.pkg for tsi in ts_items]
  File "/usr/lib/python3.6/site-packages/dnf-plugins/post-transaction-actions.py", line 134, in <listcomp>
    pkgs = [tsi.pkg for tsi in ts_items]
  File "/usr/lib/python3.6/site-packages/dnf/db/history.py", line 157, in pkg
    return self._swdb.rpm._swdb_ti_pkg[self._item]
KeyError: <libdnf.transaction.TransactionItem; proxy of <Swig Object of type 'libdnf::TransactionItemPtr *' at 0x7f4970c22db0> >
```

Version-Release number of selected component (if applicable):
4.7.0-4.el8

How reproducible:
Always.

Steps to Reproduce:
1. Upgrade packages with DNF.
2. Notice traceback in DNF output.

Actual results:

```
[sa@secure5 ~]$ sudo dnf update
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 3:12:08 ago on Tue Nov 16 07:00:35 2021.
Dependencies resolved.
================================================================================
 Package      Arch   Version               Repository                      Size
================================================================================
Installing:
 kernel       x86_64 4.18.0-348.2.1.el8_5  rhel-8-for-x86_64-baseos-rpms  7.0 M
 kernel-core  x86_64 4.18.0-348.2.1.el8_5  rhel-8-for-x86_64-baseos-rpms   38 M
 kernel-modules
              x86_64 4.18.0-348.2.1.el8_5  rhel-8-for-x86_64-baseos-rpms   30 M
Upgrading:
 kernel-tools x86_64 4.18.0-348.2.1.el8_5  rhel-8-for-x86_64-baseos-rpms  7.2 M
 kernel-tools-libs
              x86_64 4.18.0-348.2.1.el8_5  rhel-8-for-x86_64-baseos-rpms  7.0 M
 python3-perf x86_64 4.18.0-348.2.1.el8_5  rhel-8-for-x86_64-baseos-rpms  7.1 M
Removing:
 kernel       x86_64 4.18.0-305.19.1.el8_4 @rhel-8-for-x86_64-baseos-rpms   0  
 kernel-core  x86_64 4.18.0-305.19.1.el8_4 @rhel-8-for-x86_64-baseos-rpms  67 M
 kernel-modules
              x86_64 4.18.0-305.19.1.el8_4 @rhel-8-for-x86_64-baseos-rpms  22 M

Transaction Summary
================================================================================
Install  3 Packages
Upgrade  3 Packages
Remove   3 Packages

Total download size: 96 M
Is this ok [y/N]: y
Downloading Packages:
(1/6): kernel-4.18.0-348.2.1.el8_5.x86_64.rpm    13 MB/s | 7.0 MB     00:00    
(2/6): kernel-core-4.18.0-348.2.1.el8_5.x86_64.  29 MB/s |  38 MB     00:01    
(3/6): kernel-modules-4.18.0-348.2.1.el8_5.x86_  19 MB/s |  30 MB     00:01    
(4/6): python3-perf-4.18.0-348.2.1.el8_5.x86_64 6.2 MB/s | 7.1 MB     00:01    
(5/6): kernel-tools-4.18.0-348.2.1.el8_5.x86_64  16 MB/s | 7.2 MB     00:00    
(6/6): kernel-tools-libs-4.18.0-348.2.1.el8_5.x  17 MB/s | 7.0 MB     00:00    
--------------------------------------------------------------------------------
Total                                            46 MB/s |  96 MB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Running scriptlet: kernel-core-4.18.0-348.2.1.el8_5.x86_64                1/1 
  Installing       : kernel-core-4.18.0-348.2.1.el8_5.x86_64               1/12 
  Running scriptlet: kernel-core-4.18.0-348.2.1.el8_5.x86_64               1/12 
  Installing       : kernel-modules-4.18.0-348.2.1.el8_5.x86_64            2/12 
  Running scriptlet: kernel-modules-4.18.0-348.2.1.el8_5.x86_64            2/12 
  Upgrading        : kernel-tools-libs-4.18.0-348.2.1.el8_5.x86_64         3/12 
  Running scriptlet: kernel-tools-libs-4.18.0-348.2.1.el8_5.x86_64         3/12 
  Upgrading        : kernel-tools-4.18.0-348.2.1.el8_5.x86_64              4/12 
  Installing       : kernel-4.18.0-348.2.1.el8_5.x86_64                    5/12 
  Upgrading        : python3-perf-4.18.0-348.2.1.el8_5.x86_64              6/12 
  Erasing          : kernel-4.18.0-305.19.1.el8_4.x86_64                   7/12 
  Running scriptlet: kernel-4.18.0-305.19.1.el8_4.x86_64                   7/12 
  Cleanup          : kernel-tools-4.18.0-348.el8.x86_64                    8/12 
  Erasing          : kernel-modules-4.18.0-305.19.1.el8_4.x86_64           9/12 
  Running scriptlet: kernel-modules-4.18.0-305.19.1.el8_4.x86_64           9/12 
  Running scriptlet: kernel-core-4.18.0-305.19.1.el8_4.x86_64             10/12 
  Erasing          : kernel-core-4.18.0-305.19.1.el8_4.x86_64             10/12 
  Cleanup          : kernel-tools-libs-4.18.0-348.el8.x86_64              11/12 
  Running scriptlet: kernel-tools-libs-4.18.0-348.el8.x86_64              11/12 
  Cleanup          : python3-perf-4.18.0-348.el8.x86_64                   12/12 
  Running scriptlet: kernel-core-4.18.0-348.2.1.el8_5.x86_64              12/12 
  Running scriptlet: python3-perf-4.18.0-348.el8.x86_64                   12/12 
  Verifying        : kernel-4.18.0-348.2.1.el8_5.x86_64                    1/12 
  Verifying        : kernel-core-4.18.0-348.2.1.el8_5.x86_64               2/12 
  Verifying        : kernel-modules-4.18.0-348.2.1.el8_5.x86_64            3/12 
  Verifying        : python3-perf-4.18.0-348.2.1.el8_5.x86_64              4/12 
  Verifying        : python3-perf-4.18.0-348.el8.x86_64                    5/12 
  Verifying        : kernel-tools-4.18.0-348.2.1.el8_5.x86_64              6/12 
  Verifying        : kernel-tools-4.18.0-348.el8.x86_64                    7/12 
  Verifying        : kernel-tools-libs-4.18.0-348.2.1.el8_5.x86_64         8/12 
  Verifying        : kernel-tools-libs-4.18.0-348.el8.x86_64               9/12 
  Verifying        : kernel-4.18.0-305.19.1.el8_4.x86_64                  10/12 
  Verifying        : kernel-core-4.18.0-305.19.1.el8_4.x86_64             11/12 
  Verifying        : kernel-modules-4.18.0-305.19.1.el8_4.x86_64          12/12 
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/dnf/plugin.py", line 104, in _caller
    getattr(plugin, method)()
  File "/usr/lib/python3.6/site-packages/dnf-plugins/post-transaction-actions.py", line 134, in transaction
    pkgs = [tsi.pkg for tsi in ts_items]
  File "/usr/lib/python3.6/site-packages/dnf-plugins/post-transaction-actions.py", line 134, in <listcomp>
    pkgs = [tsi.pkg for tsi in ts_items]
  File "/usr/lib/python3.6/site-packages/dnf/db/history.py", line 157, in pkg
    return self._swdb.rpm._swdb_ti_pkg[self._item]
KeyError: <libdnf.transaction.TransactionItem; proxy of <Swig Object of type 'libdnf::TransactionItemPtr *' at 0x7f4970c22db0> >


Upgraded:
  kernel-tools-4.18.0-348.2.1.el8_5.x86_64                                      
  kernel-tools-libs-4.18.0-348.2.1.el8_5.x86_64                                 
  python3-perf-4.18.0-348.2.1.el8_5.x86_64                                      
Installed:
  kernel-4.18.0-348.2.1.el8_5.x86_64                                            
  kernel-core-4.18.0-348.2.1.el8_5.x86_64                                       
  kernel-modules-4.18.0-348.2.1.el8_5.x86_64                                    
Removed:
  kernel-4.18.0-305.19.1.el8_4.x86_64                                           
  kernel-core-4.18.0-305.19.1.el8_4.x86_64                                      
  kernel-modules-4.18.0-305.19.1.el8_4.x86_64                                   

Complete!
[sa@secure5 ~]$ echo $?
0
```

Comment 1 Imre Jonk 2022-01-31 15:56:42 UTC
Hi, any update on this?

Comment 2 Jaroslav Mracek 2022-03-15 14:03:11 UTC
It looks like an issue when postransaction action plugin is used. Because of low occurrence of the issue we will revisit the bug around 8.9 planning.

Comment 3 Jaroslav Mracek 2022-04-26 09:17:28 UTC
Please can you provide setting of postransaction action plugin?

Comment 4 Jaroslav Mracek 2022-04-26 09:31:37 UTC
May be we have fix for the issue - https://github.com/rpm-software-management/dnf-plugins-core/pull/454. Please can you verify whether it helps or not?

Comment 5 Imre Jonk 2022-04-28 12:09:49 UTC
Yes this has definitely something to do with the post-transaction actions DNF plugin, thanks for pointing it out. I need some more time to pinpoint the exact issue and write down the steps to reproduce it, as well as trying the fix you linked to. I'll keep you informed.

Comment 6 Imre Jonk 2022-04-29 15:28:27 UTC
Hi Jaroslav, I have some additional information for you:

- The patch works, much appreciated!
- The issue only occurs during a kernel update, and only when the maximum number of kernels configured in `installonly_limit` (default: 3) will be exceeded, which causes the removal of the oldest kernel.
- The exit code of the failed DNF update command is, strangely enough, zero. DNF even shows a summary of upgraded packages and the string 'Completed!' at the bottom. When there are many package updates, you have to scroll back to see the KeyError.

I'm still verifying whether our DNF post-transaction actions configuration has any impact on this issue. I hope to have the answer for you this Monday.

Comment 7 Imre Jonk 2022-05-02 11:53:49 UTC
Here are updated instructions to reproduce the problem:

1. Perform a minimal install of RHEL 8.5 in a virtual machine and register it using subscription-manager.
2. Install the post-transaction actions DNF plugin:
   `# dnf install python3-dnf-plugin-post-transaction-actions`
3. Install a test action that doesn't really do anything:
   `# echo "*:any:/bin/true" > /etc/dnf/plugins/post-transaction-actions.d/test.action`
4. Install two newer kernel packages, bringing the total number of installed kernels to three:
   `# dnf install kernel-4.18.0-348.2.1.el8_5 kernel-4.18.0-348.7.1.el8_5`
5. Install a fourth kernel package, which exceeds the `installonly_limit` of three, causing the old 4.18.0-348.el8 kernel package to be removed:
   `# dnf install kernel-4.18.0-348.12.2.el8_5`
6. Observe the KeyError.

The KeyError does not occur when step 3 is skipped. Also, when the KeyError occurs, none of the post-transaction actions get executed.

Comment 8 Imre Jonk 2022-05-02 14:01:58 UTC
Our systems, and systems of our customers, rely on the post-transaction actions plugin working properly. We currently work around this issue with a custom dnf-plugins-core package with your patch applied. That package has version 4.0.21-4.1.el8. It would be great if the next Red Hat update has this patch applied as well, so that the next update will go smoothly.

Comment 9 Jaroslav Mracek 2022-05-03 13:23:03 UTC
Perfect, thanks for the nice and clear reproducer. I wish I have always so many useful information.

Comment 10 Jaroslav Mracek 2022-05-04 10:50:29 UTC
I created a CI test according to provided reproducer: https://github.com/rpm-software-management/ci-dnf-stack/pull/1093

Comment 19 errata-xmlrpc 2022-11-08 10:53:15 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (dnf-plugins-core bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7759