Project

Profile

Help

Issue #3567

closed

get_resource() doesn't throw a ValidationError if you feed it a non-specific URI

Added by dalley about 6 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
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 #1

Updated by dalley about 6 years ago

  • Subject changed from get_resource() doesn't throw a ValidationError if you feed it a non-detail URI to get_resource() doesn't throw a ValidationError if you feed it a non-specific URI
  • Status changed from NEW to POST
  • Assignee set to dalley
  • Sprint set to Sprint 35

Added by dalley about 6 years ago

Revision 338f0a33 | View on GitHub

get_resource() shouldn't accept a non-resource URI

closes #3567 https://pulp.plan.io/issues/3567

Added by dalley about 6 years ago

Revision 338f0a33 | View on GitHub

get_resource() shouldn't accept a non-resource URI

closes #3567 https://pulp.plan.io/issues/3567

Actions #2

Updated by dalley about 6 years ago

  • Status changed from POST to MODIFIED

Added by dalley about 6 years ago

Revision f77e0e5d | View on GitHub

Add more unit tests around NamedModelViewSet

closes #3567 https://pulp.plan.io/issues/3568

Actions #3

Updated by dalley about 6 years ago

Actions #4

Updated by daviddavis almost 5 years ago

  • Sprint/Milestone set to 3.0.0
Actions #5

Updated by bmbouter almost 5 years ago

  • Tags deleted (Pulp 3)
Actions #6

Updated by bmbouter over 4 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF