Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: dropping user with default privilege's error message is more clear #77016

Conversation

RichardJCai
Copy link
Contributor

@RichardJCai RichardJCai commented Feb 24, 2022

Release note (sql change): When dropping a user that has default privileges,
the error message now includes which database and schema the default privileges
are defined in.

Error message now includes the database name and schema name for which the default privileges are defined.

The UX is still not ideal here but this is a good first step.

Example:

pq: role testuser4 cannot be dropped because some objects depend on it
  owner of default privileges on new sequences belonging to role testuser4 in database testdb2 in schema s
  privileges for default privileges on new sequences belonging to role testuser3 in database testdb2 in schema s
  privileges for default privileges on new sequences for all roles in database testdb2 in schema public
  privileges for default privileges on new sequences for all roles in database testdb2 in schema s
  HINT: USE testdb2; ALTER DEFAULT PRIVILEGES FOR ROLE testuser4 IN SCHEMA S REVOKE ALL ON SEQUENCES FROM testuser3;
  USE testdb2; ALTER DEFAULT PRIVILEGES FOR ROLE testuser3 IN SCHEMA S REVOKE ALL ON SEQUENCES FROM testuser4;
  USE testdb2; ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA PUBLIC REVOKE ALL ON SEQUENCES FROM testuser4;
  USE testdb2; ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA S REVOKE ALL ON SEQUENCES FROM testuser4;

@RichardJCai RichardJCai requested review from rafiss and a team February 24, 2022 23:24
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@RichardJCai RichardJCai added backport-21.1.x Flags PRs that need to be backported to 21.1. backport-21.2.x Flags PRs that need to be backported to 21.2. labels Feb 24, 2022
)
} else {
err = errors.Newf(
"privileges for default privileges on new %s belonging to role %s",
objectType, role.Role,
wrapErrorMsgWithSchemaName("privileges for default privileges on new %s belonging to role %s in database %s"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to use errors.WithDetail here? should we add a errors.WithHint to suggest what syntax can be used to remove the default privileges?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add a hint for each but I'm slightly afraid it might make it too verbose, but I think we'd rather err that way than making it more obfuscated so I'm for it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah alright but I'd say the table info should be a detail

@RichardJCai RichardJCai force-pushed the make_default_privileges_error_msg_more_clear branch from dbade07 to 586f44c Compare February 25, 2022 18:02
@blathers-crl blathers-crl bot requested a review from otan February 25, 2022 18:02
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! is the 21.1 backport actually needed? there's no default privs there right?

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @otan, @RichardJCai, and @ZhouXing19)

Release note (sql change): When dropping a user that has default privileges,
the error message now includes which database and schema the default privileges
are defined in.

Additionally a hint is given to show exactly how to remove the default privileges.
Example:
pq: role testuser4 cannot be dropped because some objects depend on it
owner of default privileges on new sequences belonging to role testuser4 in database testdb2 in schema s
privileges for default privileges on new sequences belonging to role testuser3 in database testdb2 in schema s
privileges for default privileges on new sequences for all roles in database testdb2 in schema public
privileges for default privileges on new sequences for all roles in database testdb2 in schema s
HINT: USE testdb2; ALTER DEFAULT PRIVILEGES FOR ROLE testuser4 IN SCHEMA S REVOKE ALL ON SEQUENCES FROM testuser3;
USE testdb2; ALTER DEFAULT PRIVILEGES FOR ROLE testuser3 IN SCHEMA S REVOKE ALL ON SEQUENCES FROM testuser4;
USE testdb2; ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA PUBLIC REVOKE ALL ON SEQUENCES FROM testuser4;
USE testdb2; ALTER DEFAULT PRIVILEGES FOR ALL ROLES IN SCHEMA S REVOKE ALL ON SEQUENCES FROM testuser4;
@RichardJCai RichardJCai force-pushed the make_default_privileges_error_msg_more_clear branch from 586f44c to 93337c8 Compare February 25, 2022 19:11
@RichardJCai
Copy link
Contributor Author

lgtm! is the 21.1 backport actually needed? there's no default privs there right?

Yeah don't need 21.1

@RichardJCai RichardJCai removed the backport-21.1.x Flags PRs that need to be backported to 21.1. label Feb 25, 2022
@RichardJCai
Copy link
Contributor Author

TFTR!

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Feb 26, 2022

Build succeeded:

@craig craig bot merged commit 8e72482 into cockroachdb:master Feb 26, 2022
@blathers-crl
Copy link

blathers-crl bot commented Feb 26, 2022

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 93337c8 to blathers/backport-release-21.2-77016: POST https://api.github.com/repos/cockroachlabs/cockroach/merges: 403 Resource not accessible by integration []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 21.2.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-21.2.x Flags PRs that need to be backported to 21.2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants