-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
MultipleObjectsReturned in core.views.serve.serve.docs #4350
Comments
Wondering if not passing the user to public is the correct fix. |
I have encountered this sometimes locally, but I wasn't able to replicate, and I think this has never happened in production. |
Also, this had already been reported before #2613 |
Thanks for the heads up. I'll try to cook a test and a PR then. |
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. So just don't pass the user to the public() method fixes to get the code work. Fix readthedocs#4350
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. So just don't pass the user to the public() method fixes to get the code work. Fix readthedocs#4350
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
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
Just a short question, why is this issue closed? To me it appears that the fix has not been applied to readthedocs but to the fork only. |
@p3trus thanks for checking, it has been closed automatically by github :) |
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 private and the user is not admin - serve the file if the version is private and the user is the admin Fix readthedocs#4350
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 private and the user is not admin - serve the file if the version is private and the user is the admin Fix readthedocs#4350
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 private and the user is not admin - serve the file if the version is private and the user is the admin Fix readthedocs#4350
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Any plans to merge this bugfix in the near future? |
@p3trus this is the bug not the PR |
I know but the docsitalia team already fixed it. |
@p3trus you probably missed I'm the one who is trying to get this merged :) |
@xrmx I didn't mean to sound nagging. Just wanted to know the timeframe if there is any. |
@p3trus asking for ETA is nagging :) If you look at the PR you'll see clearly stated that it's not merged because coverage tests fail. They fail because code does not do what the tests expect and I suspect even before the proposed changes. |
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 private and the user is not admin - serve the file if the version is private and the user is the admin Fix readthedocs#4350
When filtering using `public` and using a user, the queryset hit this https://github.com/rtfd/readthedocs.org/blob/45df7fd0da44be9eab3c0cb2888f6a9a15421fc5/readthedocs/builds/querysets.py#L22-L24 When the user is authenticated, we call to `get_objects_for_user` which gets all the versions from all the user's projects. Overriding any previous filter (`project.versions` in this case) We don't see this in production because we serve from another domain. And we don't see this in the corporate site because we override the serve_docs view. Fix readthedocs#4350 Closes readthedocs#4356
We get this exception while trying to serve some docs:
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:
The text was updated successfully, but these errors were encountered: