Skip to content

404: skip not built versions #10681

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

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions readthedocs/proxito/tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,26 @@ def test_custom_404_skips_not_built_versions(self, storage_open):
self.assertEqual(response.status_code, 404)
storage_open.assert_not_called()

@mock.patch.object(BuildMediaFileSystemStorageTest, "open")
def test_custom_404_doesnt_exist_in_storage(self, storage_open):
storage_open.side_effect = FileNotFoundError
get(
HTMLFile,
project=self.project,
version=self.version,
path="404.html",
name="404.html",
)
response = self.client.get(
reverse(
"proxito_404_handler",
kwargs={"proxito_path": "/en/latest/not-found"},
),
headers={"host": "project.readthedocs.io"},
)
self.assertEqual(response.status_code, 404)
storage_open.assert_called_once_with("html/project/latest/404.html")

@mock.patch.object(BuildMediaFileSystemStorageTest, "open")
def test_404_storage_serves_custom_404_sphinx_single_html(self, storage_open):
self.project.versions.update(active=True, built=True)
Expand Down
14 changes: 9 additions & 5 deletions readthedocs/proxito/views/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,15 @@ def _get_custom_404_page(self, request, project, version=None):
version_slug_404=version_404.slug,
storage_filename_path=storage_filename_path,
)
resp = HttpResponse(
build_media_storage.open(storage_filename_path).read()
)
resp.status_code = 404
return resp
try:
content = build_media_storage.open(storage_filename_path).read()
except FileNotFoundError:
log.warning(
"File not found in storage. File out of sync with DB.",
file=storage_filename_path,
)
return None
return HttpResponse(content, status=404)
return None

def _get_index_file_redirect(self, request, project, version, filename, full_path):
Expand Down