diff --git a/CHANGES/195.bugfix b/CHANGES/195.bugfix new file mode 100644 index 0000000000..1442d43b53 --- /dev/null +++ b/CHANGES/195.bugfix @@ -0,0 +1 @@ +Fix KeyError lookup in namespace and collection viewset diff --git a/galaxy_ng/app/api/ui/viewsets/collection.py b/galaxy_ng/app/api/ui/viewsets/collection.py index 14240d0bad..034aab12ed 100644 --- a/galaxy_ng/app/api/ui/viewsets/collection.py +++ b/galaxy_ng/app/api/ui/viewsets/collection.py @@ -1,5 +1,6 @@ from django.db.models import Exists, OuterRef, Q from django.core.exceptions import ObjectDoesNotExist +from django.http import Http404 from django.shortcuts import get_object_or_404 from django_filters import filters from django_filters.rest_framework import filterset, DjangoFilterBackend, OrderingFilter @@ -50,8 +51,12 @@ class CollectionViewSet( def get_queryset(self): """Returns a CollectionVersions queryset for specified distribution.""" - distro_content = self.get_distro_content(self.kwargs["path"]) - repo_version = self.get_repository_version(self.kwargs["path"]) + path = self.kwargs.get('path') + if path is None: + raise Http404("Distribution base path is required") + + distro_content = self.get_distro_content(path) + repo_version = self.get_repository_version(path) versions = CollectionVersion.objects.filter(pk__in=distro_content).values_list( "collection_id", diff --git a/galaxy_ng/app/api/v3/viewsets/namespace.py b/galaxy_ng/app/api/v3/viewsets/namespace.py index 2dc16eef5f..8dda6da8fd 100644 --- a/galaxy_ng/app/api/v3/viewsets/namespace.py +++ b/galaxy_ng/app/api/v3/viewsets/namespace.py @@ -53,8 +53,8 @@ def get_serializer_class(self): @transaction.atomic def create(self, request, *args, **kwargs): """Override to validate for name duplication before serializer validation.""" - name = request.data['name'] - if models.Namespace.objects.filter(name=name).exists(): + name = request.data.get('name') + if name and models.Namespace.objects.filter(name=name).exists(): # Ensures error raised is 409, not 400. raise ConflictError( detail={'name': f'A namespace named {name} already exists.'}