Skip to content

Commit 5bcbbd8

Browse files
committed
Use querysets from the class not from an instance
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
1 parent a215295 commit 5bcbbd8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

readthedocs/api/v2/views/footer_views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_version_compare_data(project, base_version=None):
2525
:param base_version: We assert whether or not the base_version is also the
2626
highest version in the resulting "is_highest" value.
2727
"""
28-
versions_qs = project.versions.public().filter(active=True)
28+
versions_qs = Version.objects.public(project=project)
2929

3030
# Take preferences over tags only if the project has at least one tag
3131
if versions_qs.filter(type=TAG).exists():

readthedocs/core/views/serve.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,11 @@ def serve_docs(
202202
if not version_slug:
203203
version_slug = project.get_default_version()
204204
try:
205-
version = project.versions.public(request.user).get(slug=version_slug)
205+
version = (
206+
Version.objects
207+
.public(user=request.user, project=project)
208+
.get(slug=version_slug)
209+
)
206210
except Version.DoesNotExist:
207211
# Properly raise a 404 if the version doesn't exist (or is inactive) and
208212
# a 401 if it does
@@ -409,8 +413,10 @@ def changefreqs_generator():
409413

410414
if project.translations.exists():
411415
for translation in project.translations.all():
412-
translation_versions = translation.versions.public(
413-
).values_list('slug', flat=True)
416+
translation_versions = (
417+
Version.objects.public(project=translation)
418+
.values_list('slug', flat=True)
419+
)
414420
if version.slug in translation_versions:
415421
href = project.get_docs_url(
416422
version_slug=version.slug,

0 commit comments

Comments
 (0)