Repository: pulp/pulpcore

Issue:
Remove deprecated creation_hooks interface for 3.20



Discussion:

Resolving patch:
diff --git a/pulpcore/app/access_policy.py b/pulpcore/app/access_policy.py
--- a/pulpcore/app/access_policy.py
+++ b/pulpcore/app/access_policy.py
@@ -1,6 +1,6 @@
 from rest_access_policy import AccessPolicy
+from rest_framework.exceptions import APIException
 
-from pulpcore.app.loggers import deprecation_logger
 from pulpcore.app.models import AccessPolicy as AccessPolicyModel
 from pulpcore.app.util import get_view_urlpattern, get_viewset_for_model
 from pulpcore.app.role_util import get_objects_for_user
@@ -48,19 +48,16 @@ def handle_creation_hooks(cls, obj):
         access_policy = cls.get_access_policy(viewset)
         if access_policy and access_policy.creation_hooks is not None:
             for creation_hook in access_policy.creation_hooks:
-                function = obj.REGISTERED_CREATION_HOOKS.get(creation_hook["function"])
-                if function is not None:
-                    kwargs = creation_hook.get("parameters") or {}
-                    function(**kwargs)
-                else:
-                    # Old interface deprecated for removal in 3.20
-                    function = getattr(obj, creation_hook["function"])
-                    deprecation_logger.warn(
-                        "Calling unregistered creation hooks from the access policy is deprecated"
-                        " and may be removed with pulpcore 3.20."
-                        f"[hook={creation_hook}, viewset={access_policy.viewset_name}]."
+                hook_name = creation_hook["function"]
+                try:
+                    function = obj.REGISTERED_CREATION_HOOKS[hook_name]
+                except KeyError:
+                    raise APIException(
+                        f"Creation hook '{hook_name}' was not registered for this view set."
                     )
-                    function(creation_hook.get("permissions"), creation_hook.get("parameters"))
+
+                kwargs = creation_hook.get("parameters") or {}
+                function(**kwargs)
 
     def scope_queryset(self, view, qs):
         """
diff --git a/pulpcore/app/apps.py b/pulpcore/app/apps.py
--- a/pulpcore/app/apps.py
+++ b/pulpcore/app/apps.py
@@ -197,25 +197,6 @@ def ready(self):
         post_migrate.connect(_delete_anon_user, sender=self, dispatch_uid="delete_anon_identifier")
 
 
-def _rename_permissions_assignment_workaround(access_policy, viewset):
-    from pulpcore.app.loggers import deprecation_logger
-
-    if "permissions_assignment" in access_policy:
-        deprecation_logger.warn(
-            f"In AccessPolicy for {viewset}, "
-            "the field 'permissions_assignment' has been renamed to 'creation_hooks'. This "
-            "workaround may be removed with pulpcore 3.20."
-        )
-        access_policy["creation_hooks"] = access_policy.pop("permissions_assignment")
-    if "creation_hooks" in access_policy:
-        if any(hook.get("permissions") is not None for hook in access_policy["creation_hooks"]):
-            deprecation_logger.warn(
-                f"In AccessPolicy for {viewset}, "
-                "the 'permissions' field in 'creation_hooks' is deprecated and may be removed "
-                "with pulpcore 3.20. Use the 'parameters' field instead."
-            )
-
-
 def _populate_access_policies(sender, apps, verbosity, **kwargs):
     from pulpcore.app.util import get_view_urlpattern
 
@@ -231,7 +212,6 @@ def _populate_access_policies(sender, apps, verbosity, **kwargs):
             access_policy = getattr(viewset, "DEFAULT_ACCESS_POLICY", None)
             if access_policy is not None:
                 viewset_name = get_view_urlpattern(viewset)
-                _rename_permissions_assignment_workaround(access_policy, viewset)
                 db_access_policy, created = AccessPolicy.objects.get_or_create(
                     viewset_name=viewset_name, defaults=access_policy
                 )


Test patch: