Why does dnf state: absent remove packages depending on the package too?

Using this task, I want to remove the patch package from my servers.
But after running the task, dkms is also uninstalled. Dkms depends on the patch package.

  - name: "Remove now unused patch package"
    ansible.builtin.dnf:
      name: patch
      state: absent
      allowerasing: false

The behaviour I would expect is that the task fails, stating a package depends on it, and unless that package is also explicitly mentioned in that task, it wont continue.
Instead it just removes the dkms package too. Why is that?

i tried adding allowerasing = false, even thought that should be enabled by default, and as expected it didnt change anything.

I found a stack overflow post stating similar behaviour even two years ago.

I tried installing patch explicitly, installing dkms explicitly, running the playbook and again both packages are gone.

Anyone can help me out why this happens? Is this intended behaviour, if so, why?

Thanks a lot in advance, I’m just confused why it works like that.

Im running ansible version core 2.18.2, python version 3.12.5

Because that’s how dnf works. To remove a package, it also has to remove packages that depend on that package.

vereveel-root ~ # dnf remove patch
Dependencies resolved.
================================================================================
 Package                 Arch       Version                Repository      Size
================================================================================
Removing:
 patch                   x86_64     2.7.6-16.el9           @appstream     259 k
Removing dependent packages:
 rpm-build               x86_64     4.16.1.3-37.el9        @appstream     146 k
 rpmdevtools             noarch     9.5-1.el9              @appstream     195 k