Actions
Issue #3567
closedget_resource() doesn't throw a ValidationError if you feed it a non-specific URI
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 35
Quarter:
Description
This shouldn't work. It works ONLY because only one repository exists.
[vagrant@pulp3 ~]$ http POST $REMOTE_HREF'sync/' repository=http://localhost:8000/api/v3/repositories/
HTTP/1.1 202 Accepted
Allow: POST, OPTIONS
Content-Type: application/json
Date: Sun, 15 Apr 2018 04:15:28 GMT
Server: WSGIServer/0.2 CPython/3.6.2
Vary: Accept
[
{
"_href": "http://localhost:8000/api/v3/tasks/c4ddafe1-7f3f-4695-9557-5ae96c8ce59e/",
"task_id": "c4ddafe1-7f3f-4695-9557-5ae96c8ce59e"
}
]
Make a second repo, and it blows up.
Internal Server Error: /api/v3/remotes/file/24ce2926-c3a5-43b1-85d9-e01408c54568/sync/
Traceback (most recent call last):
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/rest_framework/viewsets.py", line 103, in view
return self.dispatch(request, *args, **kwargs)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception self.raise_uncaught_exception(exc)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch response = handler(request, *args, **kwargs)
File "/home/vagrant/devel/pulp_file/pulp_file/app/viewsets.py", line 104, in sync repository = self.get_resource(repository_uri, Repository)
File "/home/vagrant/devel/pulp/pulpcore/pulpcore/app/viewsets/base.py", line 136, in get_resource return model.objects.get(**kwargs)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/vagrant/.virtualenvs/pulp/lib64/python3.6/site-packages/django/db/models/query.py", line 407, in get
(self.model._meta.object_name, num)
pulpcore.app.models.repository.MultipleObjectsReturned: get() returned more than one Repository -- it returned 2!
get_resource() needs to handle this case better.
if 'pk' in match.kwargs:
kwargs = match.kwargs
else:
kwargs = {}
for key, value in match.kwargs.items(): # <-- match.kwargs is empty, so none of this code happens
if key.endswith('_pk'):
kwargs["{}__pk".format(key[:-3])] = value
else:
kwargs[key] = value
try:
return model.objects.get(**kwargs) # <--- empty get() tries to return everything
Actions
get_resource() shouldn't accept a non-resource URI
closes #3567 https://pulp.plan.io/issues/3567