Skip to content

[BUG] REFRESH MATERIALIZED VIEW reports success and empties the view when its query fails #800

Open

Description

@jeffreyaven

Describe the bug

When the query behind a materialized view fails during REFRESH MATERIALIZED VIEW, stackql prints the HTTP error, then prints refresh materialized view completed, exits 0, and the view is left with no rows. The previous contents are lost.

To Reproduce

Uses the github provider. The first statement runs with a valid token, the refresh with an invalid one.

$ export TOKEN=<valid github token>
$ stackql exec --auth '{"github":{"type":"bearer","credentialsenvvar":"TOKEN"}}' --sqlBackend '{"dsn":"file:r.db"}' --output json "CREATE MATERIALIZED VIEW me AS SELECT login FROM github.users.users"
DDL Execution Completed

$ stackql exec --auth '{"github":{"type":"bearer","credentialsenvvar":"TOKEN"}}' --sqlBackend '{"dsn":"file:r.db"}' --output json "SELECT login FROM me"
[{"login":"jeffreyaven"}]

$ TOKEN=invalid stackql exec --auth '{"github":{"type":"bearer","credentialsenvvar":"TOKEN"}}' --sqlBackend '{"dsn":"file:r.db"}' --output json "REFRESH MATERIALIZED VIEW me"
http response status code: 401, response body: {
  "message": "Bad credentials",
  "documentation_url": "https://docs.github.com/rest",
  "status": "401"
}
refresh materialized view completed

$ stackql exec --auth '{"github":{"type":"bearer","credentialsenvvar":"TOKEN"}}' --sqlBackend '{"dsn":"file:r.db"}' --output json "SELECT login FROM me"
null

Expected behavior

The refresh is atomic: if the query fails, the view keeps its previous rows, the failure is reported instead of refresh materialized view completed, and the exit code is non-zero.

Environment

  • stackql v0.12.718 Windows (0dba3cf), Windows 11
  • github provider v26.08.00448
  • --sqlBackend '{"dsn":"file:r.db"}'

Additional context

The same thing presumably happens for any transient failure (rate limit, network), which makes REFRESH risky for a durable snapshot. Workaround: create views in a fresh file each run and never refresh.

Activity

  1. self-assigned this
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions