-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handles a PushRepository.DoesNotExist
exception
#1727
Conversation
pulp_container/app/registry_api.py
Outdated
message='Cannot create "' + path + '" push repository, another repository with ' | ||
"the same name already exists.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much information. Let's stick to raising just RepositoryInvalid(name=path, message="Repository is read-only.")
.
docs/user/guides/push-image.md
Outdated
remote content via the Pulp API. Trying to push a content with the same name of an existing | ||
"regular" repository will fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remote content via the Pulp API. Trying to push a content with the same name of an existing | |
"regular" repository will fail. | |
remote content via the Pulp API. Trying to push content with the same name as an existing | |
"regular" repository will fail. |
CHANGES/1712.bugfix
Outdated
Resolved an issue that caused an HTTP 500 error when attempting to push an image with the same name | ||
as an existing regular repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved an issue that caused an HTTP 500 error when attempting to push an image with the same name | |
as an existing regular repository. | |
Fixed an HTTP 500 error returned when pushing an image with the same name as the name of an existing read-only repository. |
pulp_container/app/registry_api.py
Outdated
distribution = serializers.ContainerDistributionSerializer.get_or_create( | ||
{"base_path": path, "name": path}, {"repository": get_url(repository)} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to catch an exception here.
pulp file distribution create --name test/mygroup/ubuntu --base-path test/mygroup/ubuntu
podman push localhost:5001/test/mygroup/ubuntu --tls-verify=false
...
[pulp] | raise ValidationError(self.errors)
[pulp] | rest_framework.exceptions.ValidationError: {'name': [ErrorDetail(string='This field must be unique.', code='unique')], 'base_path': [ErrorDetail(string='This field must be unique.', code='unique')]}
[pulp] |
[pulp] | During handling of the above exception, another exception occurred:
[pulp] |
[pulp] | Traceback (most recent call last):
[pulp] | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
[pulp] | response = get_response(request)
[pulp] | File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
[pulp] | response = wrapped_callback(request, *callback_args, **callback_kwargs)
[pulp] | File "/usr/local/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view
[pulp] | return view_func(*args, **kwargs)
[pulp] | File "/usr/local/lib/python3.9/site-packages/rest_framework/viewsets.py", line 124, in view
[pulp] | return self.dispatch(request, *args, **kwargs)
[pulp] | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
[pulp] | response = self.handle_exception(exc)
[pulp] | File "/src/pulp_container/pulp_container/app/registry_api.py", line 279, in handle_exception
[pulp] | response = super().handle_exception(exc)
[pulp] | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
[pulp] | self.raise_uncaught_exception(exc)
[pulp] | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
[pulp] | raise exc
[pulp] | File "/usr/local/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
[pulp] | response = handler(request, *args, **kwargs)
[pulp] | File "/src/pulp_container/pulp_container/app/registry_api.py", line 773, in create
[pulp] | _, repository = self.get_dr_push(request, path, create=True)
[pulp] | File "/src/pulp_container/pulp_container/app/registry_api.py", line 373, in get_dr_push
[pulp] | distribution, repository = self.create_dr(path, request)
[pulp] | File "/src/pulp_container/pulp_container/app/registry_api.py", line 405, in create_dr
[pulp] | distribution = serializers.ContainerDistributionSerializer.get_or_create(
[pulp] | File "/src/pulpcore/pulpcore/app/serializers/base.py", line 381, in get_or_create
[pulp] | result = cls.Meta.model.objects.get(**natural_key)
[pulp] | File "/usr/local/lib/python3.9/site-packages/django/db/models/manager.py", line 87, in manager_method
[pulp] | return getattr(self.get_queryset(), name)(*args, **kwargs)
[pulp] | File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 637, in get
[pulp] | raise self.model.DoesNotExist(
[pulp] | pulp_container.app.models.ContainerDistribution.DoesNotExist: ContainerDistribution matching query does not exist.
Maybe, we should start monitoring both get_or_create
calls. django.core.exceptions.ObjectDoesNotExist
would do us a favour.
92876c3
to
2691a3b
Compare
pulp_container/app/registry_api.py
Outdated
{"base_path": path, "name": path}, {"repository": get_url(repository)} | ||
) | ||
except models.ContainerDistribution.DoesNotExist: | ||
raise InvalidRequest(message="ContainerDistribution does not exist.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can raise again RepositoryInvalid. The distribution exists. But, it has a different type than anticipated and I have no idea what error message we should pass to the client...
2691a3b
to
65461d7
Compare
pulp_container/app/registry_api.py
Outdated
name=path, | ||
message="Cannot push to " | ||
+ path | ||
+ ". Another plugin with the same distribution name already exists.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is a pulp-container pull-through distribution that has the same name? Is it still another plugin? 😈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
65461d7
to
b4501fa
Compare
pulp_container/app/registry_api.py
Outdated
try: | ||
repository = serializers.ContainerPushRepositorySerializer.get_or_create( | ||
{"name": path} | ||
) | ||
except models.ContainerPushRepository.DoesNotExist: | ||
raise RepositoryInvalid(name=path, message="Repository is read-only.") | ||
|
||
try: | ||
distribution = serializers.ContainerDistributionSerializer.get_or_create( | ||
{"base_path": path, "name": path}, {"repository": get_url(repository)} | ||
) | ||
except models.ContainerDistribution.DoesNotExist: | ||
raise RepositoryInvalid(name=path, message="Repository is ready-only.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try: | |
repository = serializers.ContainerPushRepositorySerializer.get_or_create( | |
{"name": path} | |
) | |
except models.ContainerPushRepository.DoesNotExist: | |
raise RepositoryInvalid(name=path, message="Repository is read-only.") | |
try: | |
distribution = serializers.ContainerDistributionSerializer.get_or_create( | |
{"base_path": path, "name": path}, {"repository": get_url(repository)} | |
) | |
except models.ContainerDistribution.DoesNotExist: | |
raise RepositoryInvalid(name=path, message="Repository is ready-only.") | |
try: | |
repository = serializers.ContainerPushRepositorySerializer.get_or_create( | |
{"name": path} | |
) | |
distribution = serializers.ContainerDistributionSerializer.get_or_create( | |
{"base_path": path, "name": path}, {"repository": get_url(repository)} | |
) | |
except ObjectDoesNotExist: | |
raise RepositoryInvalid(name=path, message="Repository is ready-only.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum... actually, it seems like it does not work:
...
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 637, in get
raise self.model.DoesNotExist(
pulp_container.app.models.ContainerDistribution.DoesNotExist: ContainerDistribution matching query does not exist.
...
File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 637, in get
raise self.model.DoesNotExist(
pulp_container.app.models.ContainerPullThroughRemote.DoesNotExist: ContainerPullThroughRemote matching query does not exist.
the django ObjectDoesNotExist
exception did not catch the ContainerDistribution.DoesNotExist
and/or ContainerPullThroughRemote.DoesNotExist
exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, the above exception is not related with the proposed change.
We opened a new issue (#1729) to investigate it.
b4501fa
to
3d2e657
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple and straightforward! 🐁
fixes: #1712