Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core: fix MultipleObjectsReturned in core.views.serve.serve.docs
We get this exception while trying to serve some docs: MultipleObjectsReturned: get() returned more than one Version -- it returned 2! File "django/core/handlers/base.py", line 149, in get_response response = self.process_exception_by_middleware(e, request) File "django/core/handlers/base.py", line 147, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "readthedocs/core/views/serve.py", line 96, in inner_view return view_func(request, project=project, *args, **kwargs) File "readthedocs/core/views/serve.py", line 74, in inner_view return view_func(request, subproject=subproject, *args, **kwargs) File "readthedocs/core/views/serve.py", line 156, in serve_docs version = project.versions.public(request.user).get(slug=version_slug) File "django/db/models/query.py", line 391, in get (self.model._meta.object_name, num) The view code looks legit at a first look but there's a huge side effect of the user filtering in the public() method. It does not filter the projects by user but it adds to the queryset all the other user projects which is not what we need here. Instead simplify the code to: - return 404 if the requested version does not exist - return 401 if the version is not private and the user is not admin - search the file if the version is private and the user is the admin Fix readthedocs#4350
- Loading branch information