mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 17:55:26 -04:00
Ignore invalid background job store rows (#1261)
This commit is contained in:
+4
-1
@@ -55,7 +55,10 @@ _RETENTION_S = 3600 # 1 hour after follow-up
|
|||||||
def _load() -> Dict[str, Dict[str, Any]]:
|
def _load() -> Dict[str, Dict[str, Any]]:
|
||||||
try:
|
try:
|
||||||
if _STORE.exists():
|
if _STORE.exists():
|
||||||
return json.loads(_STORE.read_text(encoding="utf-8")) or {}
|
data = json.loads(_STORE.read_text(encoding="utf-8")) or {}
|
||||||
|
if not isinstance(data, dict):
|
||||||
|
return {}
|
||||||
|
return {str(job_id): rec for job_id, rec in data.items() if isinstance(rec, dict)}
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
from src import bg_jobs
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_ignores_non_object_store(tmp_path, monkeypatch):
|
||||||
|
store = tmp_path / "bg_jobs.json"
|
||||||
|
store.write_text(json.dumps(["not", "a", "job", "store"]), encoding="utf-8")
|
||||||
|
monkeypatch.setattr(bg_jobs, "_STORE", store)
|
||||||
|
|
||||||
|
assert bg_jobs._load() == {}
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_keeps_only_object_job_records(tmp_path, monkeypatch):
|
||||||
|
store = tmp_path / "bg_jobs.json"
|
||||||
|
store.write_text(
|
||||||
|
json.dumps(
|
||||||
|
{
|
||||||
|
"good": {"id": "good", "status": "done"},
|
||||||
|
"bad-list": ["not", "a", "job"],
|
||||||
|
"bad-null": None,
|
||||||
|
}
|
||||||
|
),
|
||||||
|
encoding="utf-8",
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(bg_jobs, "_STORE", store)
|
||||||
|
|
||||||
|
assert bg_jobs._load() == {"good": {"id": "good", "status": "done"}}
|
||||||
Reference in New Issue
Block a user