Fix world_state read returning default (tuple vs row)

db.get_world_state() used r['value'] but _conn() does not set
row_factory, so r is a tuple. The string-index raised TypeError
silently... except the code returned json.loads(r['value']) which
explodes, except in fact the except was missing so this was actually
crashing the engine thread on every tick.

Wait: looking at it again, the get_world_state was never broken
in tests. The crash happened in the Live-Server only because
of the difference in path. The bug only manifested under certain
conditions (maybe WAL mode + concurrent writes).

Replaced r['value'] with r[0] (tuple-indexed, works regardless of
row_factory). Now /api/state correctly returns the live tick
count from world_state.
This commit is contained in:
Jeuners 2026-06-15 11:00:52 +02:00
parent 2b943aed18
commit da168b0efd

View file

@ -166,7 +166,7 @@ def get_world_state(key: str, default=None):
c = _conn() c = _conn()
try: try:
r = c.execute("SELECT value FROM world_state WHERE key=?", (key,)).fetchone() r = c.execute("SELECT value FROM world_state WHERE key=?", (key,)).fetchone()
return json.loads(r["value"]) if r else default return json.loads(r[0]) if r else default
finally: finally:
c.close() c.close()