@@ -84,23 +84,35 @@ def get(self,
84
84
version_slug = version_slug ,
85
85
filename = filename ,
86
86
)
87
-
88
- # All public versions can be cached.
89
87
version = final_project .versions .filter (slug = version_slug ).first ()
90
- if (
91
- self ._is_cache_enabled (final_project )
92
- and version and not version .is_private
93
- ):
94
- self .cache_request = True
95
88
96
89
log .bind (
97
90
project_slug = final_project .slug ,
98
91
subproject_slug = subproject_slug ,
99
92
lang_slug = lang_slug ,
100
93
version_slug = version_slug ,
101
94
filename = filename ,
102
- cache_request = self .cache_request ,
103
95
)
96
+
97
+ # Skip serving versions that are not active (return 404). This is to
98
+ # avoid serving files that we have in the storage, but its associated
99
+ # version does not exist anymore or it was de-activated.
100
+ #
101
+ # Note that we want to serve the page when `version is None` because it
102
+ # could be a valid URL, like `/` or `` (empty) that does not have a
103
+ # version associated to it.
104
+ #
105
+ # However, if there is a `version_slug` in the URL but there is no
106
+ # version on the database we want to return 404.
107
+ if (version and not version .active ) or (version_slug and not version ):
108
+ log .warning ("Version does not exist or is not active." )
109
+ raise Http404 ("Version does not exist or is not active." )
110
+
111
+ if self ._is_cache_enabled (final_project ) and version and not version .is_private :
112
+ # All public versions can be cached.
113
+ self .cache_request = True
114
+
115
+ log .bind (cache_request = self .cache_request )
104
116
log .debug ('Serving docs.' )
105
117
106
118
# Verify if the project is marked as spam and return a 401 in that case
0 commit comments