Repository: pulp/pulpcore

Issue:
Remove NamedModelViewSet.extract_pk and pulpcore.plugin.actions.raise_for_unknown_content_units
In https://github.com/pulp/pulpcore/pull/3552, we deprecated `NamedModelViewSet.extract_pk` and `pulpcore.plugin.actions.raise_for_unknown_content_units` in favour of `pulpcore.plugin.util.extract_pk` and `pulpcore.plugin.util.raise_for_unknown_content_units`, respectively. The change was required to prevent circular imports while enhancing the validation on the `modify` endpoint.


Discussion:
This is a follow-up task to remove deprecated functions/methods that should no longer be available for users as of v3.25.

Resolving patch:
diff --git a/pulpcore/app/viewsets/base.py b/pulpcore/app/viewsets/base.py
--- a/pulpcore/app/viewsets/base.py
+++ b/pulpcore/app/viewsets/base.py
@@ -16,7 +16,6 @@
 from rest_framework.serializers import ValidationError as DRFValidationError, ListField, CharField
 
 from pulpcore.app import tasks
-from pulpcore.app.loggers import deprecation_logger
 from pulpcore.app.models import MasterModel
 from pulpcore.app.models.role import GroupRole, UserRole
 from pulpcore.app.response import OperationPostponedResponse
@@ -199,43 +198,6 @@ def get_resource(uri, model=None):
                 detail=_("URI {u} is not a valid {m}.").format(u=uri, m=model._meta.model_name)
             )
 
-    @staticmethod
-    def extract_pk(uri):
-        """
-        Resolve a resource URI to a simple PK value.
-
-        Provides a means to resolve an href passed in a POST body to a primary key.
-        Doesn't assume anything about whether the resource corresponding to the URI
-        passed in actually exists.
-
-        Note:
-            Cannot be used with nested URIs where the PK of the final resource is not present.
-            e.g. RepositoryVersion URI consists of repository PK and version number - no
-            RepositoryVersion PK is present within the URI.
-
-        Args:
-            uri (str): A resource URI.
-
-        Returns:
-            primary_key (uuid.uuid4): The primary key of the resource extracted from the URI.
-
-        Raises:
-            rest_framework.exceptions.ValidationError: on invalid URI.
-        """
-        deprecation_logger.warning(
-            "NamedModelViewSet.extract_pk() is deprecated and will be removed in pulpcore==3.25; "
-            "use pulpcore.plugin.util.extract_pk() instead."
-        )
-        try:
-            match = resolve(urlparse(uri).path)
-        except Resolver404:
-            raise DRFValidationError(detail=_("URI not valid: {u}").format(u=uri))
-
-        try:
-            return match.kwargs["pk"]
-        except KeyError:
-            raise DRFValidationError("URI does not contain an unqualified resource PK")
-
     @classmethod
     def is_master_viewset(cls):
         # ViewSet isn't related to a model, so it can't represent a master model
diff --git a/pulpcore/plugin/actions.py b/pulpcore/plugin/actions.py
--- a/pulpcore/plugin/actions.py
+++ b/pulpcore/plugin/actions.py
@@ -1,11 +1,7 @@
-from gettext import gettext as _
-
 from drf_spectacular.utils import extend_schema
 from rest_framework.decorators import action
-from rest_framework.serializers import ValidationError
 
 from pulpcore.app import tasks
-from pulpcore.app.loggers import deprecation_logger
 from pulpcore.app.models import RepositoryVersion
 from pulpcore.app.response import OperationPostponedResponse
 from pulpcore.app.serializers import (
@@ -15,7 +11,7 @@
 from pulpcore.tasking.tasks import dispatch
 
 
-__all__ = ["ModifyRepositoryActionMixin", "raise_for_unknown_content_units"]
+__all__ = ["ModifyRepositoryActionMixin"]
 
 
 class ModifyRepositoryActionMixin:
@@ -49,29 +45,3 @@ def modify(self, request, pk):
             },
         )
         return OperationPostponedResponse(task, request)
-
-
-def raise_for_unknown_content_units(existing_content_units, content_units_pks_hrefs):
-    """Verify if all the specified content units were found in the database.
-
-    Args:
-        existing_content_units (pulpcore.plugin.models.Content): Content filtered by
-            specified_content_units.
-        content_units_pks_hrefs (dict): An original dictionary of pk-href pairs that
-            are used for the verification.
-    Raises:
-        ValidationError: If some of the referenced content units are not present in the database
-    """
-    deprecation_logger.warning(
-        "pulpcore.plugin.actions.raise_for_unknown_content_units() is deprecated and will be "
-        "removed in pulpcore==3.25; use pulpcore.plugin.util.raise_for_unknown_content_units()."
-    )
-    existing_content_units_pks = existing_content_units.values_list("pk", flat=True)
-    existing_content_units_pks = set(map(str, existing_content_units_pks))
-
-    missing_pks = set(content_units_pks_hrefs.keys()) - existing_content_units_pks
-    if missing_pks:
-        missing_hrefs = [content_units_pks_hrefs[pk] for pk in missing_pks]
-        raise ValidationError(
-            _("Could not find the following content units: {}").format(missing_hrefs)
-        )


Test patch: