Remove Orphans task fails

Problem:
Remove Orphans tasks fail with
(“Cannot delete some instances of model ‘Repository’ because they are referenced through protected foreign keys: ‘Variant.repository’, ‘RpmRepository.repository_ptr’.”, {<Variant: AppStream>})

I was hoping the last update would’ve resolved this error, but it seems it wasn’t the same issue that was fixed.

Expected outcome:
No error

Foreman and Proxy versions:
Foreman 3.2.1
Katello 4.4.1

Foreman and Proxy plugin versions:

Distribution and version:
CentOS 7 - all available updates installed

Other relevant data:

jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: pulp [417db05bdfc3482c8f1355a8a7567c0f]: pulpcore.tasking.pulpcore_worker:INFO: Task e6c467f5-0389-4a30-8b50-bdc6c7afbddf failed (("Cannot delete some instances of model 'Repository' because they are referenced through protected foreign keys: 'Variant.repository', 'RpmRepository.repository_ptr'.", {<Variant: AppStream>}))
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: pulp [417db05bdfc3482c8f1355a8a7567c0f]: pulpcore.tasking.pulpcore_worker:INFO:   File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulpcore/tasking/pulpcore_worker.py", line 380, in _perform_task
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: result = func(*args, **kwargs)
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulpcore/app/tasks/orphan.py", line 66, in orphan_cleanup
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: c.delete()
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/query.py", line 746, in delete
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: deleted, _rows_count = collector.delete()
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/deletion.py", line 435, in delete
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: signals.post_delete.send(
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 180, in send
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: return [
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 181, in <listcomp>
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: (receiver, receiver(signal=self, sender=sender, **named))
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulp_rpm/app/models/distribution.py", line 340, in cleanup_subrepos
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: subrepo.delete()
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/rh/rh-python38/root/usr/lib64/python3.8/contextlib.py", line 75, in inner
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: return func(*args, **kwds)
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django_lifecycle/mixins.py", line 147, in delete
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: value = super().delete(*args, **kwargs)
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/base.py", line 966, in delete
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: collector.collect([self], keep_parents=keep_parents)
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: File "/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/deletion.py", line 302, in collect
jún 16 14:32:17 foreman.example.com pulpcore-worker-3[23789]: raise ProtectedError(

I also started this to appear, and there is already a issue for that if I saw that correctly:

https://github.com/pulp/pulp_rpm/issues/2459

Yup, this will be fixed in a new release of pulp_rpm soon.

Out of curiosity, do you have any idea which repository might have been responsible? Which ones you might have deleted recently?

Only repo i can think of is some NodeSource repos