Skip to content

data: list commands skip migrations on fresh/empty DB → 'no such table: assets' #88

Closed

Description

@ffroliva

Summary

After deleting (or first-time creation of) `<GFLOW_CLI_HOME>/gflow.db`, `gflow data list profiles` crashes:

```
Data store error: Data store error: Catalog query failed: no such table: assets
```

Cause

`src/gflow_cli/data/queries.py:24-37` (`_safe_db`) opens a raw `sqlite3.connect(db_path)` and never invokes `DataStore.apply_migrations()`. `sqlite3.connect` auto-creates an empty DB file if missing, but the schema is never installed → first query fails with `no such table: assets`.

By contrast `gflow_cli/data/store.py:153` `DataStore.open` always runs migrations on a fresh file. `data media` (which goes through `DataStore.open`) works on the empty DB; `data list` does not.

Repro (Windows path; same on Linux/macOS)

```bash
$ rm "$(.venv/Scripts/python.exe -c 'from gflow_cli.config import get_settings; print(get_settings().resolved_db_path())')"
$ gflow data list profiles
Data store error: Data store error: Catalog query failed: no such table: assets
$ gflow data list videos # same crash for all list subcommands
```

Impact

Proposed fix

Two options:

Option A — `_safe_db` delegates to `DataStore.open`. Replace the raw `sqlite3.connect` in `_safe_db` with `DataStore.open(db_path)`, yield `store.conn`. Reuses the existing migration path; consistent with `data media`.

Option B — query functions defend against missing schema. Catch `sqlite3.OperationalError("no such table")` and return empty lists. Mirrors how a fresh catalog "has no rows."

Recommendation: Option A. Treating the DB-open path as the single source of truth keeps migrations in one place and prevents future schema-drift bugs.

Files

  • `src/gflow_cli/data/queries.py` — replace `_safe_db` body with `DataStore.open` delegation
  • `tests/test_data_queries.py` — new test: empty DB path → `list_*` returns `[]` without raising
  • `tests/cli/test_cli_data.py` — CLI-level test: `data list videos` on missing-file DB exits 0 with no rows

Acceptance

After deleting the catalog DB, `gflow data list profiles | images | videos | projects` all return empty output (or "no rows") with exit 0 — no `no such table` errors.

Discovered while cleaning the polluted DB to recover from #86 (2026-05-26).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions