prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Export is not locking on the exported repositories
  SSIA
  
  --- 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/viewsets/exporter.py`
  Content:
  ```
  1 from django_filters.rest_framework import filters
  2 
  3 from drf_spectacular.utils import extend_schema
  4 from rest_framework import mixins
  5 
  6 from pulpcore.app.models import (
  7     Export,
  8     Exporter,
  9     FilesystemExport,
  10     FilesystemExporter,
  11     Publication,
  12     PulpExport,
  13     PulpExporter,
  14     RepositoryVersion,
  15 )
  16 
  17 from pulpcore.app.serializers import (
  18     AsyncOperationResponseSerializer,
  19     ExportSerializer,
  20     ExporterSerializer,
  21     FilesystemExporterSerializer,
  22     FilesystemExportSerializer,
  23     PulpExporterSerializer,
  24     PulpExportSerializer,
  25 )
  26 
  27 from pulpcore.app.tasks.export import fs_publication_export, fs_repo_version_export, pulp_export
  28 
  29 from pulpcore.app.viewsets import (
  30     AsyncRemoveMixin,
  31     AsyncUpdateMixin,
  32     BaseFilterSet,
  33     NamedModelViewSet,
  34 )
  35 from pulpcore.app.viewsets.base import NAME_FILTER_OPTIONS
  36 from pulpcore.plugin.tasking import dispatch
  37 from pulpcore.app.response import OperationPostponedResponse
  38 
  39 
  40 class ExporterFilter(BaseFilterSet):
  41     """
  42     Plugin file system exporter filter should:
  43      - inherit from this class
  44      - add any specific filters if needed
  45      - define a `Meta` class which should:
  46        - specify a plugin remote model for which filter is defined
  47        - extend `fields` with specific ones
  48     """
  49 
  50     name = filters.CharFilter()
  51 
  52     class Meta:
  53         model = Exporter
  54         fields = {
  55             "name": NAME_FILTER_OPTIONS,
  56         }
  57 
  58 
  59 class ExporterViewSet(
  60     NamedModelViewSet,
  61     mixins.CreateModelMixin,
  62     AsyncUpdateMixin,
  63     mixins.RetrieveModelMixin,
  64     mixins.ListModelMixin,
  65     AsyncRemoveMixin,
  66 ):
  67     """
  68     ViewSet for viewing exporters.
  69     """
  70 
  71     queryset = Exporter.objects.all()
  72     serializer_class = ExporterSerializer
  73     endpoint_name = "exporters"
  74     router_lookup = "exporter"
  75     filterset_class = ExporterFilter
  76 
  77 
  78 class PulpExporterViewSet(ExporterViewSet):
  79     """
  80     ViewSet for viewing PulpExporters.
  81     """
  82 
  83     endpoint_name = "pulp"
  84     serializer_class = PulpExporterSerializer
  85     queryset = PulpExporter.objects.all()
  86 
  87 
  88 class FilesystemExporterViewSet(ExporterViewSet):
  89     """
  90     Endpoint for managing FilesystemExporters. FilesystemExporters are provided as a tech preview.
  91     """
  92 
  93     endpoint_name = "filesystem"
  94     serializer_class = FilesystemExporterSerializer
  95     queryset = FilesystemExporter.objects.all()
  96 
  97 
  98 class ExportViewSet(
  99     NamedModelViewSet,
  100     mixins.CreateModelMixin,
  101     mixins.RetrieveModelMixin,
  102     mixins.ListModelMixin,
  103     mixins.DestroyModelMixin,
  104 ):
  105     """
  106     ViewSet for viewing exports from an Exporter.
  107     """
  108 
  109     endpoint_name = "exports"
  110     nest_prefix = "exporters"
  111     router_lookup = "export"
  112     lookup_field = "pk"
  113     parent_lookup_kwargs = {"exporter_pk": "exporter__pk"}
  114     serializer_class = ExportSerializer
  115     queryset = Export.objects.all()
  116     parent_viewset = ExporterViewSet
  117 
  118 
  119 class PulpExportViewSet(ExportViewSet):
  120     """
  121     ViewSet for viewing exports from a PulpExporter.
  122     """
  123 
  124     parent_viewset = PulpExporterViewSet
  125     serializer_class = PulpExportSerializer
  126     queryset = PulpExport.objects.all()
  127 
  128     @extend_schema(
  129         request=PulpExportSerializer,
  130         description="Trigger an asynchronous task to export a set of repositories",
  131         responses={202: AsyncOperationResponseSerializer},
  132     )
  133     def create(self, request, exporter_pk):
  134         """
  135         Generates a Task to export the set of repositories assigned to a specific PulpExporter.
  136         """
  137         # Validate Exporter
  138         exporter = PulpExporter.objects.get(pk=exporter_pk).cast()
  139         ExporterSerializer.validate_path(exporter.path, check_is_dir=True)
  140 
  141         # Validate Export
  142         serializer = PulpExportSerializer(data=request.data, context={"exporter": exporter})
  143         serializer.is_valid(raise_exception=True)
  144 
  145         # Invoke the export
  146         task = dispatch(
  147             pulp_export,
  148             exclusive_resources=[exporter],
  149             kwargs={"exporter_pk": str(exporter.pk), "params": request.data},
  150         )
  151 
  152         return OperationPostponedResponse(task, request)
  153 
  154 
  155 class FilesystemExportViewSet(ExportViewSet):
  156     """
  157     Endpoint for managing FilesystemExports. This endpoint is provided as a tech preview.
  158     """
  159 
  160     parent_viewset = FilesystemExporterViewSet
  161     serializer_class = FilesystemExportSerializer
  162     queryset = FilesystemExport.objects.all()
  163 
  164     @extend_schema(
  165         request=FilesystemExportSerializer,
  166         description="Trigger an asynchronous task to export files to the filesystem",
  167         responses={202: AsyncOperationResponseSerializer},
  168     )
  169     def create(self, request, exporter_pk):
  170         """
  171         Generates a Task to export files to the filesystem.
  172         """
  173         # Validate Exporter
  174         exporter = FilesystemExporter.objects.get(pk=exporter_pk).cast()
  175         ExporterSerializer.validate_path(exporter.path, check_is_dir=True)
  176 
  177         # Validate Export
  178         serializer = FilesystemExportSerializer(data=request.data, context={"exporter": exporter})
  179         serializer.is_valid(raise_exception=True)
  180 
  181         if request.data.get("publication"):
  182             publication = self.get_resource(request.data["publication"], Publication)
  183 
  184             task = dispatch(
  185                 fs_publication_export,
  186                 exclusive_resources=[exporter],
  187                 kwargs={"exporter_pk": exporter.pk, "publication_pk": publication.pk},
  188             )
  189         else:
  190             repo_version = self.get_resource(request.data["repository_version"], RepositoryVersion)
  191 
  192             task = dispatch(
  193                 fs_repo_version_export,
  194                 exclusive_resources=[exporter],
  195                 kwargs={"exporter_pk": str(exporter.pk), "repo_version_pk": repo_version.pk},
  196             )
  197 
  198         return OperationPostponedResponse(task, request)
  199
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/pulpcore/app/viewsets/exporter.py b/pulpcore/app/viewsets/exporter.py
  --- a/pulpcore/app/viewsets/exporter.py
  +++ b/pulpcore/app/viewsets/exporter.py
  @@ -146,6 +146,7 @@
           task = dispatch(
               pulp_export,
               exclusive_resources=[exporter],
  +            shared_resources=exporter.repositories.all(),
               kwargs={"exporter_pk": str(exporter.pk), "params": request.data},
           )
  
verification_info: {"golden_diff": "diff --git a/pulpcore/app/viewsets/exporter.py b/pulpcore/app/viewsets/exporter.py\n--- a/pulpcore/app/viewsets/exporter.py\n+++ b/pulpcore/app/viewsets/exporter.py\n@@ -146,6 +146,7 @@\n         task = dispatch(\n             pulp_export,\n             exclusive_resources=[exporter],\n+            shared_resources=exporter.repositories.all(),\n             kwargs={\"exporter_pk\": str(exporter.pk), \"params\": request.data},\n         )\n", "issue": "Export is not locking on the exported repositories\nSSIA\n", "before_files": [{"content": "from django_filters.rest_framework import filters\n\nfrom drf_spectacular.utils import extend_schema\nfrom rest_framework import mixins\n\nfrom pulpcore.app.models import (\n    Export,\n    Exporter,\n    FilesystemExport,\n    FilesystemExporter,\n    Publication,\n    PulpExport,\n    PulpExporter,\n    RepositoryVersion,\n)\n\nfrom pulpcore.app.serializers import (\n    AsyncOperationResponseSerializer,\n    ExportSerializer,\n    ExporterSerializer,\n    FilesystemExporterSerializer,\n    FilesystemExportSerializer,\n    PulpExporterSerializer,\n    PulpExportSerializer,\n)\n\nfrom pulpcore.app.tasks.export import fs_publication_export, fs_repo_version_export, pulp_export\n\nfrom pulpcore.app.viewsets import (\n    AsyncRemoveMixin,\n    AsyncUpdateMixin,\n    BaseFilterSet,\n    NamedModelViewSet,\n)\nfrom pulpcore.app.viewsets.base import NAME_FILTER_OPTIONS\nfrom pulpcore.plugin.tasking import dispatch\nfrom pulpcore.app.response import OperationPostponedResponse\n\n\nclass ExporterFilter(BaseFilterSet):\n    \"\"\"\n    Plugin file system exporter filter should:\n     - inherit from this class\n     - add any specific filters if needed\n     - define a `Meta` class which should:\n       - specify a plugin remote model for which filter is defined\n       - extend `fields` with specific ones\n    \"\"\"\n\n    name = filters.CharFilter()\n\n    class Meta:\n        model = Exporter\n        fields = {\n            \"name\": NAME_FILTER_OPTIONS,\n        }\n\n\nclass ExporterViewSet(\n    NamedModelViewSet,\n    mixins.CreateModelMixin,\n    AsyncUpdateMixin,\n    mixins.RetrieveModelMixin,\n    mixins.ListModelMixin,\n    AsyncRemoveMixin,\n):\n    \"\"\"\n    ViewSet for viewing exporters.\n    \"\"\"\n\n    queryset = Exporter.objects.all()\n    serializer_class = ExporterSerializer\n    endpoint_name = \"exporters\"\n    router_lookup = \"exporter\"\n    filterset_class = ExporterFilter\n\n\nclass PulpExporterViewSet(ExporterViewSet):\n    \"\"\"\n    ViewSet for viewing PulpExporters.\n    \"\"\"\n\n    endpoint_name = \"pulp\"\n    serializer_class = PulpExporterSerializer\n    queryset = PulpExporter.objects.all()\n\n\nclass FilesystemExporterViewSet(ExporterViewSet):\n    \"\"\"\n    Endpoint for managing FilesystemExporters. FilesystemExporters are provided as a tech preview.\n    \"\"\"\n\n    endpoint_name = \"filesystem\"\n    serializer_class = FilesystemExporterSerializer\n    queryset = FilesystemExporter.objects.all()\n\n\nclass ExportViewSet(\n    NamedModelViewSet,\n    mixins.CreateModelMixin,\n    mixins.RetrieveModelMixin,\n    mixins.ListModelMixin,\n    mixins.DestroyModelMixin,\n):\n    \"\"\"\n    ViewSet for viewing exports from an Exporter.\n    \"\"\"\n\n    endpoint_name = \"exports\"\n    nest_prefix = \"exporters\"\n    router_lookup = \"export\"\n    lookup_field = \"pk\"\n    parent_lookup_kwargs = {\"exporter_pk\": \"exporter__pk\"}\n    serializer_class = ExportSerializer\n    queryset = Export.objects.all()\n    parent_viewset = ExporterViewSet\n\n\nclass PulpExportViewSet(ExportViewSet):\n    \"\"\"\n    ViewSet for viewing exports from a PulpExporter.\n    \"\"\"\n\n    parent_viewset = PulpExporterViewSet\n    serializer_class = PulpExportSerializer\n    queryset = PulpExport.objects.all()\n\n    @extend_schema(\n        request=PulpExportSerializer,\n        description=\"Trigger an asynchronous task to export a set of repositories\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def create(self, request, exporter_pk):\n        \"\"\"\n        Generates a Task to export the set of repositories assigned to a specific PulpExporter.\n        \"\"\"\n        # Validate Exporter\n        exporter = PulpExporter.objects.get(pk=exporter_pk).cast()\n        ExporterSerializer.validate_path(exporter.path, check_is_dir=True)\n\n        # Validate Export\n        serializer = PulpExportSerializer(data=request.data, context={\"exporter\": exporter})\n        serializer.is_valid(raise_exception=True)\n\n        # Invoke the export\n        task = dispatch(\n            pulp_export,\n            exclusive_resources=[exporter],\n            kwargs={\"exporter_pk\": str(exporter.pk), \"params\": request.data},\n        )\n\n        return OperationPostponedResponse(task, request)\n\n\nclass FilesystemExportViewSet(ExportViewSet):\n    \"\"\"\n    Endpoint for managing FilesystemExports. This endpoint is provided as a tech preview.\n    \"\"\"\n\n    parent_viewset = FilesystemExporterViewSet\n    serializer_class = FilesystemExportSerializer\n    queryset = FilesystemExport.objects.all()\n\n    @extend_schema(\n        request=FilesystemExportSerializer,\n        description=\"Trigger an asynchronous task to export files to the filesystem\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def create(self, request, exporter_pk):\n        \"\"\"\n        Generates a Task to export files to the filesystem.\n        \"\"\"\n        # Validate Exporter\n        exporter = FilesystemExporter.objects.get(pk=exporter_pk).cast()\n        ExporterSerializer.validate_path(exporter.path, check_is_dir=True)\n\n        # Validate Export\n        serializer = FilesystemExportSerializer(data=request.data, context={\"exporter\": exporter})\n        serializer.is_valid(raise_exception=True)\n\n        if request.data.get(\"publication\"):\n            publication = self.get_resource(request.data[\"publication\"], Publication)\n\n            task = dispatch(\n                fs_publication_export,\n                exclusive_resources=[exporter],\n                kwargs={\"exporter_pk\": exporter.pk, \"publication_pk\": publication.pk},\n            )\n        else:\n            repo_version = self.get_resource(request.data[\"repository_version\"], RepositoryVersion)\n\n            task = dispatch(\n                fs_repo_version_export,\n                exclusive_resources=[exporter],\n                kwargs={\"exporter_pk\": str(exporter.pk), \"repo_version_pk\": repo_version.pk},\n            )\n\n        return OperationPostponedResponse(task, request)\n", "path": "pulpcore/app/viewsets/exporter.py"}], "after_files": [{"content": "from django_filters.rest_framework import filters\n\nfrom drf_spectacular.utils import extend_schema\nfrom rest_framework import mixins\n\nfrom pulpcore.app.models import (\n    Export,\n    Exporter,\n    FilesystemExport,\n    FilesystemExporter,\n    Publication,\n    PulpExport,\n    PulpExporter,\n    RepositoryVersion,\n)\n\nfrom pulpcore.app.serializers import (\n    AsyncOperationResponseSerializer,\n    ExportSerializer,\n    ExporterSerializer,\n    FilesystemExporterSerializer,\n    FilesystemExportSerializer,\n    PulpExporterSerializer,\n    PulpExportSerializer,\n)\n\nfrom pulpcore.app.tasks.export import fs_publication_export, fs_repo_version_export, pulp_export\n\nfrom pulpcore.app.viewsets import (\n    AsyncRemoveMixin,\n    AsyncUpdateMixin,\n    BaseFilterSet,\n    NamedModelViewSet,\n)\nfrom pulpcore.app.viewsets.base import NAME_FILTER_OPTIONS\nfrom pulpcore.plugin.tasking import dispatch\nfrom pulpcore.app.response import OperationPostponedResponse\n\n\nclass ExporterFilter(BaseFilterSet):\n    \"\"\"\n    Plugin file system exporter filter should:\n     - inherit from this class\n     - add any specific filters if needed\n     - define a `Meta` class which should:\n       - specify a plugin remote model for which filter is defined\n       - extend `fields` with specific ones\n    \"\"\"\n\n    name = filters.CharFilter()\n\n    class Meta:\n        model = Exporter\n        fields = {\n            \"name\": NAME_FILTER_OPTIONS,\n        }\n\n\nclass ExporterViewSet(\n    NamedModelViewSet,\n    mixins.CreateModelMixin,\n    AsyncUpdateMixin,\n    mixins.RetrieveModelMixin,\n    mixins.ListModelMixin,\n    AsyncRemoveMixin,\n):\n    \"\"\"\n    ViewSet for viewing exporters.\n    \"\"\"\n\n    queryset = Exporter.objects.all()\n    serializer_class = ExporterSerializer\n    endpoint_name = \"exporters\"\n    router_lookup = \"exporter\"\n    filterset_class = ExporterFilter\n\n\nclass PulpExporterViewSet(ExporterViewSet):\n    \"\"\"\n    ViewSet for viewing PulpExporters.\n    \"\"\"\n\n    endpoint_name = \"pulp\"\n    serializer_class = PulpExporterSerializer\n    queryset = PulpExporter.objects.all()\n\n\nclass FilesystemExporterViewSet(ExporterViewSet):\n    \"\"\"\n    Endpoint for managing FilesystemExporters. FilesystemExporters are provided as a tech preview.\n    \"\"\"\n\n    endpoint_name = \"filesystem\"\n    serializer_class = FilesystemExporterSerializer\n    queryset = FilesystemExporter.objects.all()\n\n\nclass ExportViewSet(\n    NamedModelViewSet,\n    mixins.CreateModelMixin,\n    mixins.RetrieveModelMixin,\n    mixins.ListModelMixin,\n    mixins.DestroyModelMixin,\n):\n    \"\"\"\n    ViewSet for viewing exports from an Exporter.\n    \"\"\"\n\n    endpoint_name = \"exports\"\n    nest_prefix = \"exporters\"\n    router_lookup = \"export\"\n    lookup_field = \"pk\"\n    parent_lookup_kwargs = {\"exporter_pk\": \"exporter__pk\"}\n    serializer_class = ExportSerializer\n    queryset = Export.objects.all()\n    parent_viewset = ExporterViewSet\n\n\nclass PulpExportViewSet(ExportViewSet):\n    \"\"\"\n    ViewSet for viewing exports from a PulpExporter.\n    \"\"\"\n\n    parent_viewset = PulpExporterViewSet\n    serializer_class = PulpExportSerializer\n    queryset = PulpExport.objects.all()\n\n    @extend_schema(\n        request=PulpExportSerializer,\n        description=\"Trigger an asynchronous task to export a set of repositories\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def create(self, request, exporter_pk):\n        \"\"\"\n        Generates a Task to export the set of repositories assigned to a specific PulpExporter.\n        \"\"\"\n        # Validate Exporter\n        exporter = PulpExporter.objects.get(pk=exporter_pk).cast()\n        ExporterSerializer.validate_path(exporter.path, check_is_dir=True)\n\n        # Validate Export\n        serializer = PulpExportSerializer(data=request.data, context={\"exporter\": exporter})\n        serializer.is_valid(raise_exception=True)\n\n        # Invoke the export\n        task = dispatch(\n            pulp_export,\n            exclusive_resources=[exporter],\n            shared_resources=exporter.repositories.all(),\n            kwargs={\"exporter_pk\": str(exporter.pk), \"params\": request.data},\n        )\n\n        return OperationPostponedResponse(task, request)\n\n\nclass FilesystemExportViewSet(ExportViewSet):\n    \"\"\"\n    Endpoint for managing FilesystemExports. This endpoint is provided as a tech preview.\n    \"\"\"\n\n    parent_viewset = FilesystemExporterViewSet\n    serializer_class = FilesystemExportSerializer\n    queryset = FilesystemExport.objects.all()\n\n    @extend_schema(\n        request=FilesystemExportSerializer,\n        description=\"Trigger an asynchronous task to export files to the filesystem\",\n        responses={202: AsyncOperationResponseSerializer},\n    )\n    def create(self, request, exporter_pk):\n        \"\"\"\n        Generates a Task to export files to the filesystem.\n        \"\"\"\n        # Validate Exporter\n        exporter = FilesystemExporter.objects.get(pk=exporter_pk).cast()\n        ExporterSerializer.validate_path(exporter.path, check_is_dir=True)\n\n        # Validate Export\n        serializer = FilesystemExportSerializer(data=request.data, context={\"exporter\": exporter})\n        serializer.is_valid(raise_exception=True)\n\n        if request.data.get(\"publication\"):\n            publication = self.get_resource(request.data[\"publication\"], Publication)\n\n            task = dispatch(\n                fs_publication_export,\n                exclusive_resources=[exporter],\n                kwargs={\"exporter_pk\": exporter.pk, \"publication_pk\": publication.pk},\n            )\n        else:\n            repo_version = self.get_resource(request.data[\"repository_version\"], RepositoryVersion)\n\n            task = dispatch(\n                fs_repo_version_export,\n                exclusive_resources=[exporter],\n                kwargs={\"exporter_pk\": str(exporter.pk), \"repo_version_pk\": repo_version.pk},\n            )\n\n        return OperationPostponedResponse(task, request)\n", "path": "pulpcore/app/viewsets/exporter.py"}]}