# Open WebUI `updated_at` Integer Corruption Fix

## Symptoms
Open WebUI fails to start with:
```
TypeError: fromisoformat: argument must be str
```
Full traceback: SQLAlchemy `config.py` → `STATE.load()` → querying `ConfigTable` → `str_to_datetime` processor → `fromisoformat` on an integer.

## Root Cause
Open WebUI's `config.updated_at` column stores a **datetime string** (`2026-06-04 19:32:30`) when properly written, but can store an **integer Unix timestamp** (`1782594088`) when written by a certain code path (e.g., direct SQLite writes, botched update, or container restart at an unlucky moment).

SQLAlchemy's query layer expects all `DATETIME` columns to return strings for `fromisoformat()`. An integer causes an uncaught `TypeError` during row construction — before any user code runs.

## Fix
If the container is running, fix via docker exec:
```bash
docker exec open-webui python3 -c "
import sqlite3, datetime
conn = sqlite3.connect('/app/backend/data/webui.db')
row = conn.execute('SELECT id, updated_at FROM config').fetchone()
if isinstance(row[1], int):
    dt_str = datetime.datetime.fromtimestamp(row[1]).strftime('%Y-%m-%d %H:%M:%S')
    conn.execute('UPDATE config SET updated_at = ? WHERE id = ?', (dt_str, row[0]))
    conn.commit()
    print(f'Fixed: updated_at {row[1]} -> {dt_str}')
else:
    print('No fix needed: updated_at is already string:', row[1])
"
```

If the container won't start (restart loop), stop it and fix the mounted DB directly:
```bash
docker stop open-webui
python3 -c "
import sqlite3, datetime
conn = sqlite3.connect('/home/rurouni/openwebui-data/webui.db')
row = conn.execute('SELECT id, updated_at FROM config').fetchone()
if isinstance(row[1], int):
    dt_str = datetime.datetime.fromtimestamp(row[1]).strftime('%Y-%m-%d %H:%M:%S')
    conn.execute('UPDATE config SET updated_at = ? WHERE id = ?', (dt_str, row[0]))
    conn.commit()
    print(f'Fixed')
else:
    print('Already a string')
conn.close()
"
docker start open-webui
```

## Prevention
- Always use Docker exec or the host-side SQLite mount for batch DB writes
- Avoid writing to the `config` table with raw SQL — use the Open WebUI API when possible
- If writing directly, ensure `updated_at` uses a datetime string format, not an integer timestamp
