You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] REFRESH MATERIALIZED VIEW reports success and empties the view when its query fails #800
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.
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