We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove orphans: Repository matching query does not exist.
**Version**
```
$ rpm -qa | grep tfm-rubygem-pulp
tfm-rubygem-pulp_certguard_client-1.5.0-1.el7.noarch
tfm-rubygem-pulp_ansible_client-0.13.1-1.el7.noarch
tfm-rubygem-pulp_deb_client-2.18.0-1.el7.noarch
tfm-rubygem-pulp_rpm_client-3.17.4-1.el7.noarch
tfm-rubygem-pulp_python_client-3.6.0-1.el7.noarch
tfm-rubygem-pulp_ostree_client-2.0.0-0.1.a1.el7.noarch
tfm-rubygem-pulpcore_client-3.18.5-1.el7.noarch
tfm-rubygem-pulp_container_client-2.10.3-1.el7.noarch
tfm-rubygem-pulp_file_client-1.10.0-1.el7.noarch

$ rpm -qa | grep katello-4
tfm-rubygem-katello-4.5.0-1.el7.noarch
katello-4.5.0-1.el7.noarch
```

**Describe the bug**
Running `foreman-rake katello:delete_orphaned_content RAILS_ENV=production` creates two tasks.
One of the tasks gets stuck in _paused_ with the following error: `Repository matching query does not exist.`


**To Reproduce**

- Run 
  `foreman-rake katello:delete_orphaned_content RAILS_ENV=production`.

- After a few minutes run 
  `hammer --no-headers --output json task list  --order 'started_at DESC' --search 'state = "paused"'`

**Expected behavior**
We expected both tasks to run successfully.

**Additional context**
We had to manually apply this patch: https://github.com/pulp/pulp_rpm/pull/2619 - before that, we had his same issue: https://github.com/pulp/pulp_rpm/issues/2459 .

```
$ hammer --no-headers --output json task list  --order 'started_at DESC' --search 'state = "paused" '
[
  {
    "ID": "a8aae19c-7c62-4a60-ab12-935687e3723e",
    "Action": "Remove orphans ",
    "State": "paused",
    "Result": "error",
    "Started at": "2022-07-21 15:29:02 UTC",
    "Ended at": null,
    "Duration": "00:02:29.56437",
    "Owner": "foreman_admin",
    "Task errors": [
      "Repository matching query does not exist."
    ]
  }
]
```
```
$ http_pulp /pulp/api/v3/tasks/e7df82c7-cb38-4fac-a28a-edd8842b3b69/
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Correlation-ID
Allow: GET, PATCH, DELETE, HEAD, OPTIONS
Connection: Keep-Alive
Content-Length: 3335
Content-Type: application/json
Correlation-ID: e1f2e082da6e401196007424799a05b5
Date: Thu, 21 Jul 2022 17:10:58 GMT
Keep-Alive: timeout=15, max=100
Referrer-Policy: same-origin
Server: gunicorn
Vary: Accept,Cookie
Via: 1.1 updates.eurotux.com
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
    "child_tasks": [],
    "created_resources": [],
    "error": {
        "description": "Repository matching query does not exist.",
        "traceback": "  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulpcore/tasking/pulpcore_worker.py\", line 410, in _perform_task\n    result = func(*args, **kwargs)\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulpcore/app/tasks/orphan.py\", line 66, in orphan_cleanup\n    c.delete()\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/query.py\", line 746, in delete\n    deleted, _rows_count = collector.delete()\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/deletion.py\", line 435, in delete\n    signals.post_delete.send(\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\", line 180, in send\n    return [\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\", line 181, in <listcomp>\n    (receiver, receiver(signal=self, sender=sender, **named))\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulp_rpm/app/models/distribution.py\", line 340, in cleanup_subrepos\n    Variant.objects.filter(repository=subrepo).delete()\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/query.py\", line 746, in delete\n    deleted, _rows_count = collector.delete()\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/deletion.py\", line 435, in delete\n    signals.post_delete.send(\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\", line 180, in send\n    return [\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\", line 181, in <listcomp>\n    (receiver, receiver(signal=self, sender=sender, **named))\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulp_rpm/app/models/distribution.py\", line 338, in cleanup_subrepos\n    subrepo = instance.repository\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py\", line 187, in __get__\n    rel_obj = self.get_object(instance)\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py\", line 154, in get_object\n    return qs.get(self.field.get_reverse_related_filter(instance))\n  File \"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/query.py\", line 435, in get\n    raise self.model.DoesNotExist(\n"
    },
    "finished_at": "2022-07-21T15:30:11.075104Z",
    "logging_cid": "ac4070d63c764578bb854f97873ba88a",
    "name": "pulpcore.app.tasks.orphan.orphan_cleanup",
    "parent_task": null,
    "progress_reports": [
        {
            "code": "clean-up.content",
            "done": 2000,
            "message": "Clean up orphan Content",
            "state": "running",
            "suffix": null,
            "total": 17098
        }
    ],
    "pulp_created": "2022-07-21T15:29:58.868921Z",
    "pulp_href": "/pulp/api/v3/tasks/e7df82c7-cb38-4fac-a28a-edd8842b3b69/",
    "reserved_resources_record": [],
    "started_at": "2022-07-21T15:29:59.335110Z",
    "state": "failed",
    "task_group": null,
    "worker": "/pulp/api/v3/workers/6ff07070-3e14-49b3-b508-a0c300683f28/"
}
```

edit: related to https://community.theforeman.org/t/delete-orphaned-content-fails/29494/6

https://bugzilla.redhat.com/show_bug.cgi?id=2115881



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pulpcore/app/views/orphans.py`
Content:
```
1 from drf_spectacular.utils import extend_schema
2 from rest_framework.views import APIView
3 
4 from pulpcore.app.loggers import deprecation_logger
5 from pulpcore.app.response import OperationPostponedResponse
6 from pulpcore.app.serializers import AsyncOperationResponseSerializer
7 from pulpcore.app.tasks import orphan_cleanup
8 from pulpcore.tasking.tasks import dispatch
9 
10 
11 class OrphansView(APIView):
12     @extend_schema(
13         description="DEPRECATED! Trigger an asynchronous task that deletes all "
14         "orphaned content and artifacts. Use the `POST /pulp/api/v3/orphans/cleanup/` call "
15         "instead.",
16         summary="Delete orphans",
17         responses={202: AsyncOperationResponseSerializer},
18     )
19     def delete(self, request, format=None):
20         """
21         Cleans up all the Content and Artifact orphans in the system
22         """
23         deprecation_logger.warning(
24             "The `DELETE /pulp/api/v3/orphans/` call is deprecated. Use"
25             "`POST /pulp/api/v3/orphans/cleanup/` instead."
26         )
27 
28         task = dispatch(orphan_cleanup)
29 
30         return OperationPostponedResponse(task, request)
31
```

Path: `pulpcore/app/viewsets/orphans.py`
Content:
```
1 from drf_spectacular.utils import extend_schema
2 from rest_framework.viewsets import ViewSet
3 
4 from pulpcore.app.response import OperationPostponedResponse
5 from pulpcore.app.serializers import AsyncOperationResponseSerializer, OrphansCleanupSerializer
6 from pulpcore.app.tasks import orphan_cleanup
7 from pulpcore.tasking.tasks import dispatch
8 
9 
10 class OrphansCleanupViewset(ViewSet):
11     serializer_class = OrphansCleanupSerializer
12 
13     @extend_schema(
14         description="Trigger an asynchronous orphan cleanup operation.",
15         responses={202: AsyncOperationResponseSerializer},
16     )
17     def cleanup(self, request):
18         """
19         Triggers an asynchronous orphan cleanup operation.
20         """
21         serializer = OrphansCleanupSerializer(data=request.data)
22         serializer.is_valid(raise_exception=True)
23 
24         content_pks = serializer.validated_data.get("content_hrefs", None)
25         orphan_protection_time = serializer.validated_data.get("orphan_protection_time")
26 
27         task = dispatch(
28             orphan_cleanup,
29             kwargs={"content_pks": content_pks, "orphan_protection_time": orphan_protection_time},
30         )
31 
32         return OperationPostponedResponse(task, request)
33
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pulpcore/app/views/orphans.py b/pulpcore/app/views/orphans.py
--- a/pulpcore/app/views/orphans.py
+++ b/pulpcore/app/views/orphans.py
@@ -25,6 +25,6 @@
             "`POST /pulp/api/v3/orphans/cleanup/` instead."
         )
 
-        task = dispatch(orphan_cleanup)
+        task = dispatch(orphan_cleanup, exclusive_resources=["/pulp/api/v3/orphans/cleanup/"])
 
         return OperationPostponedResponse(task, request)
diff --git a/pulpcore/app/viewsets/orphans.py b/pulpcore/app/viewsets/orphans.py
--- a/pulpcore/app/viewsets/orphans.py
+++ b/pulpcore/app/viewsets/orphans.py
@@ -26,6 +26,7 @@
 
         task = dispatch(
             orphan_cleanup,
+            exclusive_resources=["/pulp/api/v3/orphans/cleanup/"],
             kwargs={"content_pks": content_pks, "orphan_protection_time": orphan_protection_time},
         )

{"golden_diff": "diff --git a/pulpcore/app/views/orphans.py b/pulpcore/app/views/orphans.py\n--- a/pulpcore/app/views/orphans.py\n+++ b/pulpcore/app/views/orphans.py\n@@ -25,6 +25,6 @@\n             \"`POST /pulp/api/v3/orphans/cleanup/` instead.\"\n         )\n \n-        task = dispatch(orphan_cleanup)\n+        task = dispatch(orphan_cleanup, exclusive_resources=[\"/pulp/api/v3/orphans/cleanup/\"])\n \n         return OperationPostponedResponse(task, request)\ndiff --git a/pulpcore/app/viewsets/orphans.py b/pulpcore/app/viewsets/orphans.py\n--- a/pulpcore/app/viewsets/orphans.py\n+++ b/pulpcore/app/viewsets/orphans.py\n@@ -26,6 +26,7 @@\n \n         task = dispatch(\n             orphan_cleanup,\n+            exclusive_resources=[\"/pulp/api/v3/orphans/cleanup/\"],\n             kwargs={\"content_pks\": content_pks, \"orphan_protection_time\": orphan_protection_time},\n         )\n", "issue": "Remove orphans: Repository matching query does not exist.\n**Version**\r\n```\r\n$ rpm -qa | grep tfm-rubygem-pulp\r\ntfm-rubygem-pulp_certguard_client-1.5.0-1.el7.noarch\r\ntfm-rubygem-pulp_ansible_client-0.13.1-1.el7.noarch\r\ntfm-rubygem-pulp_deb_client-2.18.0-1.el7.noarch\r\ntfm-rubygem-pulp_rpm_client-3.17.4-1.el7.noarch\r\ntfm-rubygem-pulp_python_client-3.6.0-1.el7.noarch\r\ntfm-rubygem-pulp_ostree_client-2.0.0-0.1.a1.el7.noarch\r\ntfm-rubygem-pulpcore_client-3.18.5-1.el7.noarch\r\ntfm-rubygem-pulp_container_client-2.10.3-1.el7.noarch\r\ntfm-rubygem-pulp_file_client-1.10.0-1.el7.noarch\r\n\r\n$ rpm -qa | grep katello-4\r\ntfm-rubygem-katello-4.5.0-1.el7.noarch\r\nkatello-4.5.0-1.el7.noarch\r\n```\r\n\r\n**Describe the bug**\r\nRunning `foreman-rake katello:delete_orphaned_content RAILS_ENV=production` creates two tasks.\r\nOne of the tasks gets stuck in _paused_ with the following error: `Repository matching query does not exist.`\r\n\r\n\r\n**To Reproduce**\r\n\r\n- Run \r\n  `foreman-rake katello:delete_orphaned_content RAILS_ENV=production`.\r\n\r\n- After a few minutes run \r\n  `hammer --no-headers --output json task list  --order 'started_at DESC' --search 'state = \"paused\"'`\r\n\r\n**Expected behavior**\r\nWe expected both tasks to run successfully.\r\n\r\n**Additional context**\r\nWe had to manually apply this patch: https://github.com/pulp/pulp_rpm/pull/2619 - before that, we had his same issue: https://github.com/pulp/pulp_rpm/issues/2459 .\r\n\r\n```\r\n$ hammer --no-headers --output json task list  --order 'started_at DESC' --search 'state = \"paused\" '\r\n[\r\n  {\r\n    \"ID\": \"a8aae19c-7c62-4a60-ab12-935687e3723e\",\r\n    \"Action\": \"Remove orphans \",\r\n    \"State\": \"paused\",\r\n    \"Result\": \"error\",\r\n    \"Started at\": \"2022-07-21 15:29:02 UTC\",\r\n    \"Ended at\": null,\r\n    \"Duration\": \"00:02:29.56437\",\r\n    \"Owner\": \"foreman_admin\",\r\n    \"Task errors\": [\r\n      \"Repository matching query does not exist.\"\r\n    ]\r\n  }\r\n]\r\n```\r\n```\r\n$ http_pulp /pulp/api/v3/tasks/e7df82c7-cb38-4fac-a28a-edd8842b3b69/\r\nHTTP/1.1 200 OK\r\nAccess-Control-Expose-Headers: Correlation-ID\r\nAllow: GET, PATCH, DELETE, HEAD, OPTIONS\r\nConnection: Keep-Alive\r\nContent-Length: 3335\r\nContent-Type: application/json\r\nCorrelation-ID: e1f2e082da6e401196007424799a05b5\r\nDate: Thu, 21 Jul 2022 17:10:58 GMT\r\nKeep-Alive: timeout=15, max=100\r\nReferrer-Policy: same-origin\r\nServer: gunicorn\r\nVary: Accept,Cookie\r\nVia: 1.1 updates.eurotux.com\r\nX-Content-Type-Options: nosniff\r\nX-Frame-Options: DENY\r\n\r\n{\r\n    \"child_tasks\": [],\r\n    \"created_resources\": [],\r\n    \"error\": {\r\n        \"description\": \"Repository matching query does not exist.\",\r\n        \"traceback\": \"  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulpcore/tasking/pulpcore_worker.py\\\", line 410, in _perform_task\\n    result = func(*args, **kwargs)\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulpcore/app/tasks/orphan.py\\\", line 66, in orphan_cleanup\\n    c.delete()\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/query.py\\\", line 746, in delete\\n    deleted, _rows_count = collector.delete()\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/deletion.py\\\", line 435, in delete\\n    signals.post_delete.send(\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\\\", line 180, in send\\n    return [\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\\\", line 181, in <listcomp>\\n    (receiver, receiver(signal=self, sender=sender, **named))\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulp_rpm/app/models/distribution.py\\\", line 340, in cleanup_subrepos\\n    Variant.objects.filter(repository=subrepo).delete()\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/query.py\\\", line 746, in delete\\n    deleted, _rows_count = collector.delete()\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/deletion.py\\\", line 435, in delete\\n    signals.post_delete.send(\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\\\", line 180, in send\\n    return [\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/dispatch/dispatcher.py\\\", line 181, in <listcomp>\\n    (receiver, receiver(signal=self, sender=sender, **named))\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/pulp_rpm/app/models/distribution.py\\\", line 338, in cleanup_subrepos\\n    subrepo = instance.repository\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py\\\", line 187, in __get__\\n    rel_obj = self.get_object(instance)\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/fields/related_descriptors.py\\\", line 154, in get_object\\n    return qs.get(self.field.get_reverse_related_filter(instance))\\n  File \\\"/opt/theforeman/tfm-pulpcore/root/usr/lib/python3.8/site-packages/django/db/models/query.py\\\", line 435, in get\\n    raise self.model.DoesNotExist(\\n\"\r\n    },\r\n    \"finished_at\": \"2022-07-21T15:30:11.075104Z\",\r\n    \"logging_cid\": \"ac4070d63c764578bb854f97873ba88a\",\r\n    \"name\": \"pulpcore.app.tasks.orphan.orphan_cleanup\",\r\n    \"parent_task\": null,\r\n    \"progress_reports\": [\r\n        {\r\n            \"code\": \"clean-up.content\",\r\n            \"done\": 2000,\r\n            \"message\": \"Clean up orphan Content\",\r\n            \"state\": \"running\",\r\n            \"suffix\": null,\r\n            \"total\": 17098\r\n        }\r\n    ],\r\n    \"pulp_created\": \"2022-07-21T15:29:58.868921Z\",\r\n    \"pulp_href\": \"/pulp/api/v3/tasks/e7df82c7-cb38-4fac-a28a-edd8842b3b69/\",\r\n    \"reserved_resources_record\": [],\r\n    \"started_at\": \"2022-07-21T15:29:59.335110Z\",\r\n    \"state\": \"failed\",\r\n    \"task_group\": null,\r\n    \"worker\": \"/pulp/api/v3/workers/6ff07070-3e14-49b3-b508-a0c300683f28/\"\r\n}\r\n```\r\n\r\nedit: related to https://community.theforeman.org/t/delete-orphaned-content-fails/29494/6\r\n\r\nhttps://bugzilla.redhat.com/show_bug.cgi?id=2115881\r\n\r\n\n", "before_files": [{"content": "from drf_spectacular.utils import extend_schema\nfrom rest_framework.views import APIView\n\nfrom pulpcore.app.loggers import deprecation_logger\nfrom pulpcore.app.response import OperationPostponedResponse\nfrom pulpcore.app.serializers import AsyncOperationResponseSerializer\nfrom pulpcore.app.tasks import orphan_cleanup\nfrom pulpcore.tasking.tasks import dispatch\n\n\nclass OrphansView(APIView):\n    @extend_schema(\n        description=\"DEPRECATED! Trigger an asynchronous task that deletes all \"\n        \"orphaned content and artifacts. Use the `POST /pulp/api/v3/orphans/cleanup/` call \"\n        \"instead.\",\n        summary=\"Delete orphans\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def delete(self, request, format=None):\n        \"\"\"\n        Cleans up all the Content and Artifact orphans in the system\n        \"\"\"\n        deprecation_logger.warning(\n            \"The `DELETE /pulp/api/v3/orphans/` call is deprecated. Use\"\n            \"`POST /pulp/api/v3/orphans/cleanup/` instead.\"\n        )\n\n        task = dispatch(orphan_cleanup)\n\n        return OperationPostponedResponse(task, request)\n", "path": "pulpcore/app/views/orphans.py"}, {"content": "from drf_spectacular.utils import extend_schema\nfrom rest_framework.viewsets import ViewSet\n\nfrom pulpcore.app.response import OperationPostponedResponse\nfrom pulpcore.app.serializers import AsyncOperationResponseSerializer, OrphansCleanupSerializer\nfrom pulpcore.app.tasks import orphan_cleanup\nfrom pulpcore.tasking.tasks import dispatch\n\n\nclass OrphansCleanupViewset(ViewSet):\n    serializer_class = OrphansCleanupSerializer\n\n    @extend_schema(\n        description=\"Trigger an asynchronous orphan cleanup operation.\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def cleanup(self, request):\n        \"\"\"\n        Triggers an asynchronous orphan cleanup operation.\n        \"\"\"\n        serializer = OrphansCleanupSerializer(data=request.data)\n        serializer.is_valid(raise_exception=True)\n\n        content_pks = serializer.validated_data.get(\"content_hrefs\", None)\n        orphan_protection_time = serializer.validated_data.get(\"orphan_protection_time\")\n\n        task = dispatch(\n            orphan_cleanup,\n            kwargs={\"content_pks\": content_pks, \"orphan_protection_time\": orphan_protection_time},\n        )\n\n        return OperationPostponedResponse(task, request)\n", "path": "pulpcore/app/viewsets/orphans.py"}], "after_files": [{"content": "from drf_spectacular.utils import extend_schema\nfrom rest_framework.views import APIView\n\nfrom pulpcore.app.loggers import deprecation_logger\nfrom pulpcore.app.response import OperationPostponedResponse\nfrom pulpcore.app.serializers import AsyncOperationResponseSerializer\nfrom pulpcore.app.tasks import orphan_cleanup\nfrom pulpcore.tasking.tasks import dispatch\n\n\nclass OrphansView(APIView):\n    @extend_schema(\n        description=\"DEPRECATED! Trigger an asynchronous task that deletes all \"\n        \"orphaned content and artifacts. Use the `POST /pulp/api/v3/orphans/cleanup/` call \"\n        \"instead.\",\n        summary=\"Delete orphans\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def delete(self, request, format=None):\n        \"\"\"\n        Cleans up all the Content and Artifact orphans in the system\n        \"\"\"\n        deprecation_logger.warning(\n            \"The `DELETE /pulp/api/v3/orphans/` call is deprecated. Use\"\n            \"`POST /pulp/api/v3/orphans/cleanup/` instead.\"\n        )\n\n        task = dispatch(orphan_cleanup, exclusive_resources=[\"/pulp/api/v3/orphans/cleanup/\"])\n\n        return OperationPostponedResponse(task, request)\n", "path": "pulpcore/app/views/orphans.py"}, {"content": "from drf_spectacular.utils import extend_schema\nfrom rest_framework.viewsets import ViewSet\n\nfrom pulpcore.app.response import OperationPostponedResponse\nfrom pulpcore.app.serializers import AsyncOperationResponseSerializer, OrphansCleanupSerializer\nfrom pulpcore.app.tasks import orphan_cleanup\nfrom pulpcore.tasking.tasks import dispatch\n\n\nclass OrphansCleanupViewset(ViewSet):\n    serializer_class = OrphansCleanupSerializer\n\n    @extend_schema(\n        description=\"Trigger an asynchronous orphan cleanup operation.\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def cleanup(self, request):\n        \"\"\"\n        Triggers an asynchronous orphan cleanup operation.\n        \"\"\"\n        serializer = OrphansCleanupSerializer(data=request.data)\n        serializer.is_valid(raise_exception=True)\n\n        content_pks = serializer.validated_data.get(\"content_hrefs\", None)\n        orphan_protection_time = serializer.validated_data.get(\"orphan_protection_time\")\n\n        task = dispatch(\n            orphan_cleanup,\n            exclusive_resources=[\"/pulp/api/v3/orphans/cleanup/\"],\n            kwargs={\"content_pks\": content_pks, \"orphan_protection_time\": orphan_protection_time},\n        )\n\n        return OperationPostponedResponse(task, request)\n", "path": "pulpcore/app/viewsets/orphans.py"}]}