Runs API reads Dagster again when its SQLite run storage is locked; still locked is a 503 with Retry-After

The Postgres TEA gate got a 502 polling an ingest: logsForRun failed with
'database is locked' while the run wrote its events.
This commit is contained in:
2026-11-28 08:43:00 -06:00
parent e4967347f5
commit e434e085fe
2 changed files with 69 additions and 10 deletions
+35
View File
@@ -202,3 +202,38 @@ def test_execution_options_and_health(api):
def test_tea_eegs_analyze_validates_scope(api):
response = api.post("/tea/eegs/analyze", json={"scope": {"mode": "first_n"}})
assert response.status_code == 422
def test_a_locked_run_storage_is_read_again(monkeypatch):
"""Dagster's SQLite run storage is locked for a moment while a run writes: the read is retried,
and a storage that stays locked is a 503 the caller can retry, not a 502."""
from fastapi import HTTPException
from webapi import runs
error = {"__typename": "PythonError", "message": "OperationalError: database is locked"}
locked = {"data": {"runOrError": {"__typename": "Run"}, "logsForRun": error}}
fine = {
"data": {
"runOrError": {"__typename": "Run"},
"logsForRun": {"__typename": "EventConnection"},
}
}
answers = [locked, locked, fine]
class Answer:
status_code = 200
def __init__(self, payload):
self.payload = payload
def json(self):
return self.payload
monkeypatch.setattr(runs.time, "sleep", lambda s: None)
monkeypatch.setattr(runs.requests, "post", lambda *a, **k: Answer(answers.pop(0)))
assert runs.graphql("q", {}) == fine["data"]
monkeypatch.setattr(runs.requests, "post", lambda *a, **k: Answer(locked))
with pytest.raises(HTTPException) as raised:
runs.graphql("q", {})
assert raised.value.status_code == 503