Skip to content

Commit 16d8d97

Browse files
Restore the DB-less liveness fallback for event identities
A runtime whose database cannot be opened (the liveness smoke container ships no writable SQLite scratch directory) raised ImproperlyConfigured from _runtime_event_identity_snapshot and turned /unified/ into a 500, breaking the container smoke gate. Fall back to the build-time manifest identity snapshot for unavailable databases, matching the existing query-forbidden fallbacks, and pin the behavior with a regression test.
1 parent 48a13f0 commit 16d8d97

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

content/public_data.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ def _runtime_event_identity_snapshot() -> tuple[tuple[str, int, str], ...]:
281281
raise
282282
if isinstance(exc, RuntimeError) and "Database access not allowed" not in str(exc):
283283
raise
284-
if isinstance(exc, (AssertionError, RuntimeError)):
285-
return _manifest_event_identity_snapshot()
286-
raise ImproperlyConfigured("Public Event UUID/public-ID mapping is unavailable.") from exc
284+
# A runtime without a usable database (query-forbidden tests, the DB-less liveness
285+
# container whose SQLite scratch directory is absent) serves the build-time manifest
286+
# identities instead of failing every public page.
287+
return _manifest_event_identity_snapshot()
287288

288289

289290
def _apply_runtime_event_public_paths(

events/tests/test_identity.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from copy import deepcopy
77
from pathlib import Path
88
from typing import ClassVar
9+
from unittest import mock
910

1011
from django.core.exceptions import ImproperlyConfigured
12+
from django.db import OperationalError
1113
from django.test import TestCase
1214
from django.urls import Resolver404, resolve
1315

@@ -93,6 +95,22 @@ def test_manifest_rejects_missing_duplicate_and_renumbered_public_mappings(self)
9395
):
9496
public_projection()
9597

98+
def test_unavailable_database_serves_the_manifest_identity_snapshot(self) -> None:
99+
manifest = load_identity_manifest()
100+
expected_paths = {item.canonical_path for item in manifest.events}
101+
102+
with mock.patch.object(
103+
Event.objects,
104+
"order_by",
105+
side_effect=OperationalError("unable to open database file"),
106+
):
107+
projection = public_projection()
108+
109+
self.assertEqual(
110+
{event["public_path"] for event in projection["events"]},
111+
expected_paths,
112+
)
113+
96114
def test_manifest_import_replay_is_byte_stable_and_a_preflight_noop(self) -> None:
97115
before = tuple(Event.objects.order_by("id").values_list("id", "public_id", "slug"))
98116
first = import_identity_manifest(dry_run=True)

0 commit comments

Comments
 (0)