From c54e286ff70f311fa4e31844911a8753ffb140dd Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 30 Aug 2023 11:02:48 +0200 Subject: [PATCH 1/2] Addons: access downloads only when `version != None` Solves https://read-the-docs.sentry.io/issues/4437207301/?project=148442 --- readthedocs/proxito/views/hosting.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 4851d49778f..6ec91396a36 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -180,6 +180,9 @@ def _v0(self, project, version, build, filename): .only("slug") .order_by("slug") ) + version_downloads = ( + version.get_downloads(pretty=True).items() if version else [] + ) project_translations = ( project.translations.all().only("language").order_by("language") ) @@ -283,7 +286,7 @@ def _v0(self, project, version, build, filename): "name": name, "url": url, } - for name, url in version.get_downloads(pretty=True).items() + for name, url in version_downloads ], # TODO: find a way to get this data in a reliably way. # We don't have a simple way to map a URL to a file in the repository. From f772f53221fe84a1d880f51106c0025df1efa903 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 30 Aug 2023 12:07:07 +0200 Subject: [PATCH 2/2] Addons: empty versions and downlaods when single version project --- readthedocs/proxito/views/hosting.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/readthedocs/proxito/views/hosting.py b/readthedocs/proxito/views/hosting.py index 6ec91396a36..5c9a60e6f07 100644 --- a/readthedocs/proxito/views/hosting.py +++ b/readthedocs/proxito/views/hosting.py @@ -174,15 +174,21 @@ def _v0(self, project, version, build, filename): It tries to follow some similarity with the APIv3 for already-known resources (Project, Version, Build, etc). """ - versions_active_built_not_hidden = ( - Version.internal.public(project=project, only_active=True, only_built=True) - .exclude(hidden=True) - .only("slug") - .order_by("slug") - ) - version_downloads = ( - version.get_downloads(pretty=True).items() if version else [] - ) + version_downloads = [] + versions_active_built_not_hidden = Version.objects.none() + + if not project.single_version: + versions_active_built_not_hidden = ( + Version.internal.public( + project=project, only_active=True, only_built=True + ) + .exclude(hidden=True) + .only("slug") + .order_by("slug") + ) + if version: + version_downloads = version.get_downloads(pretty=True).items() + project_translations = ( project.translations.all().only("language").order_by("language") )