fix(tree): list databases when the role lacks CONNECT on some cluster databases#105
Open
brains-fatman wants to merge 1 commit into
Open
fix(tree): list databases when the role lacks CONNECT on some cluster databases#105brains-fatman wants to merge 1 commit into
brains-fatman wants to merge 1 commit into
Conversation
…e DBs pg_database_size() requires CONNECT on the target database (or membership in pg_read_all_stats). The database tree enumerated the whole cluster in a single query calling pg_database_size(datname) for every row, so the first inaccessible database aborted the entire SELECT — leaving the tree empty even for databases the role can access. Guard the size computation with has_database_privilege(datname, 'CONNECT') in both the databases-group and system-databases-group queries, so inaccessible databases yield a NULL size instead of erroring the whole statement. Behaviour is unchanged for privileged roles. Fixes dev-asterix#104 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@brains-fatman is attempting to deploy a commit to the asterix-dev Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
🎉 A new contributor appears! 🎉
Huge thanks to @brains-fatman for your first PR! We are thrilled to see new faces here.
While you wait for a review, feel free to join our Discord/Slack to introduce yourself. If you have any questions about the build process, just drop a comment below.
Thanks for making this project better!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #104.
src/providers/tree/loaders/ConnectionLoader.tsenumerates every database in the cluster with a single query that callspg_database_size(datname)for each row.pg_database_size()requiresCONNECTon the target database (or membership inpg_read_all_stats). When the connecting role lacksCONNECTon any database in the cluster, the first inaccessible database aborts the wholeSELECT, so the tree shows no databases at all — including the ones the role can access. The "Databases" node still reports a non-zero count, but expanding it yields an empty list.Change
Guard the size computation with
has_database_privilege(datname, 'CONNECT')in both affected queries (databases-groupandsystem-databases-group):Inaccessible databases now yield a
NULLsize instead of erroring the whole statement. Behaviour is unchanged for privileged roles — all databases are still listed, with sizes. This is a query-only change; no TypeScript or API changes.Other occurrences (intentionally not touched)
pg_database_size()is also used inhelper.ts(databaseStats, scoped tocurrent_database()) andDashboardData.ts(scoped to a single$1database). Both operate on a single database the user is connected to, so they aren't affected by this bug. Happy to extend the same guard there if you'd prefer consistency.Verification
The failing scenario was observed in a real shared/multi-tenant cluster where the connecting role lacks
CONNECTon neighbouring databases. The fix relies onhas_database_privilege()— a standard catalog function that returns a boolean and does not raise on inaccessible databases — to gatepg_database_size(), so the statement can no longer abort. For privileged roles the result set is identical to before.