-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Use querysets from the class not from an instance #5783
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
Conversation
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
Writing a test now |
@@ -25,7 +25,7 @@ def get_version_compare_data(project, base_version=None): | |||
:param base_version: We assert whether or not the base_version is also the | |||
highest version in the resulting "is_highest" value. | |||
""" | |||
versions_qs = project.versions.public().filter(active=True) | |||
versions_qs = Version.objects.public(project=project) |
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.
filter by active is the default in .org and .com querysets
'readthedocs.core.views.serve._serve_symlink_docs', | ||
new=mock.MagicMock(return_value=HttpResponse(content_type='text/html')), | ||
) | ||
def test_user_with_multiple_projects_serve_from_same_domain(self): |
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.
This test case fails on master :)
I don't fully follow the problem and the solution. What are the steps to reproduce it? The solution seems to implicitly say that "project.versions." can't be used, is that correct? |
Yes. Steps to reproduce:
The problem is that when the user is authenticated, We filter this before, but all versions get added later anyway, so that breaks the unique slug on the queryset. |
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.
Looks good. I think this is a bit cleaner as well.
Should we add the tests from #4356 here, so we can close that one too? |
@ericholscher the test that was added here replace that test, and the test for admin access was added because the other PR drops the |
Sounds good 👍 |
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 #4350
Closes #4356