diff --git a/CHANGES/1561.bugfix b/CHANGES/1561.bugfix new file mode 100644 index 000000000..f27cc207e --- /dev/null +++ b/CHANGES/1561.bugfix @@ -0,0 +1 @@ +Resolved circular import errors raised when using pulp-container as a library. diff --git a/pulp_container/app/exceptions.py b/pulp_container/app/exceptions.py index 634b610b6..8b2c998ed 100644 --- a/pulp_container/app/exceptions.py +++ b/pulp_container/app/exceptions.py @@ -1,19 +1,4 @@ -from rest_framework import status, views -from rest_framework.exceptions import ( - AuthenticationFailed, - NotAuthenticated, - NotFound, - ParseError, -) - - -def unauthorized_exception_handler(exc, context): - response = views.exception_handler(exc, context) - - if isinstance(exc, (AuthenticationFailed, NotAuthenticated)): - response.status_code = status.HTTP_401_UNAUTHORIZED - - return response +from rest_framework.exceptions import NotFound, ParseError class RepositoryNotFound(NotFound): diff --git a/pulp_container/app/registry_api.py b/pulp_container/app/registry_api.py index 3d617c0bb..365aa7a0f 100644 --- a/pulp_container/app/registry_api.py +++ b/pulp_container/app/registry_api.py @@ -43,7 +43,8 @@ from rest_framework.serializers import ModelSerializer from rest_framework.settings import api_settings from rest_framework.viewsets import ViewSet -from rest_framework.views import APIView +from rest_framework.views import APIView, exception_handler +from rest_framework.status import HTTP_401_UNAUTHORIZED from pulp_container.app import models, serializers from pulp_container.app.authorization import AuthorizationService @@ -53,7 +54,6 @@ RegistryApiCache, ) from pulp_container.app.exceptions import ( - unauthorized_exception_handler, InvalidRequest, RepositoryNotFound, RepositoryInvalid, @@ -417,6 +417,15 @@ def get_exception_handler(self): return unauthorized_exception_handler +def unauthorized_exception_handler(exc, context): + response = exception_handler(exc, context) + + if isinstance(exc, (AuthenticationFailed, NotAuthenticated)): + response.status_code = HTTP_401_UNAUTHORIZED + + return response + + class VersionView(ContainerRegistryApiMixin, APIView): """ Handles requests to the /v2/ endpoint.