Skip to content

Stop printing a trailing space after PUBLIC in GRANT and REVOKE - #2416

Open
LucaCappelletti94 wants to merge 1 commit into
apache:mainfrom
LucaCappelletti94:grantee-public-no-trailing-space
Open

Stop printing a trailing space after PUBLIC in GRANT and REVOKE#2416
LucaCappelletti94 wants to merge 1 commit into
apache:mainfrom
LucaCappelletti94:grantee-public-no-trailing-space

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Display for Grantee wrote the grantee type keyword with a trailing space baked in, then appended the name. PUBLIC is the only grantee type the parser ever builds without a name, so for it the space had nothing to follow it and GRANT SELECT ON t TO PUBLIC printed with a trailing space, which does not match the input it was parsed from.

The separator now belongs to the name rather than the keyword, so it is only written when a name follows.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review July 30, 2026 18:42

@ting-hong-shieh ting-hong-shieh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified this against main at 2f3b5b82. The trailing space reproduces, and the fix is correct.

One case worth adding to the test: the same bug shows up mid-statement, which is the more damaging form. On the merge base:

GRANT SELECT ON t TO PUBLIC, ROLE r
  ->  GRANT SELECT ON t TO PUBLIC , ROLE r

With this PR it round-trips unchanged. A trailing space is easy to miss, but a space before the comma corrupts generated SQL visibly. Since verified_stmt("GRANT SELECT ON t TO PUBLIC") still passes when only the end-of-statement case is handled, a multi-grantee case would guard the part that matters most:

all_dialects_except(|d| d.is::<MsSqlDialect>())
    .verified_stmt("GRANT SELECT ON t TO PUBLIC, ROLE r");

Two things I checked while reviewing:

  • PUBLIC really is the only grantee type the parser builds without a name — parse_grantees takes Some(name) in every other branch (src/parser/mod.rs:17758). The change does also drop the trailing space for any other type with name: None, but that is only reachable by building the AST directly, and the new output is right there too.
  • The MsSqlDialect exclusion is load-bearing: with it removed the test fails, because MsSql parses PUBLIC as grantee_type: None, name: Some("PUBLIC") while PostgreSQL gives grantee_type: Public, name: None.

cargo test --all-features at 9d5f8e21: 1584 passed, 0 failed. cargo fmt --all -- --check and cargo clippy --all-targets --all-features -- -D warnings both clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants