Fix grant macros SQL quoting (v1.0.8)#35
Merged
Conversation
… literals The Jinja tojson filter wraps values in double quotes which Snowflake interprets as identifiers causing invalid identifier errors. Replaced with format to emit proper single-quoted SQL strings. Bumped version to 1.0.8. .... Generated with [Cortex Code](https://docs.snowflake.com/en/user-guide/cortex-code/cortex-code) Co-Authored-By: Cortex Code <noreply@snowflake.com>
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes SQL quoting in grant-related dbt macros by replacing Jinja Sequence diagram for corrected SQL quoting in grant macrossequenceDiagram
actor DbtUser
participant DbtCli as dbt_cli
participant GrantMacro as grant_schema_read
participant Jinja as jinja_filters
participant Snowflake
DbtUser->>DbtCli: run-operation grant_schema_read
DbtCli->>GrantMacro: render grant_schema_read
GrantMacro->>Jinja: map("format", "'%s'") on grant_roles
Jinja-->>GrantMacro: 'ROLE_A','ROLE_B'
GrantMacro->>Snowflake: execute SQL with grantee not in ('ROLE_A','ROLE_B')
Snowflake-->>DbtCli: success (no invalid identifier error)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- You now repeat
map("format", "'%s'")in several macros; consider extracting a small helper macro for building single-quoted IN lists to keep the quoting logic consistent and easier to adjust later. - The
format("'%s'")approach assumes values never contain single quotes; if role or privilege names could include special characters, you may want to introduce a dedicated escaping/quoting helper to prevent malformed SQL.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- You now repeat `map("format", "'%s'")` in several macros; consider extracting a small helper macro for building single-quoted IN lists to keep the quoting logic consistent and easier to adjust later.
- The `format("'%s'")` approach assumes values never contain single quotes; if role or privilege names could include special characters, you may want to introduce a dedicated escaping/quoting helper to prevent malformed SQL.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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
tojsonfilter produced double-quoted strings ("ROLE_NAME") that Snowflake interprets as identifiers instead of string literalsmap('tojson')withmap("format", "'%s'")across 3 macro files (5 occurrences) to emit correct single-quoted SQL stringsTest plan
dbt run-operation grant_schema_readagainst a schema with roles to confirm noinvalid identifiererrorsdbt run-operation grant_schema_object_privilegesand verify generated SQL uses single-quoted role names_grants_get_schema_object_privshelper produces correct SQL in dry-run mode.... Generated with Cortex Code
Summary by Sourcery
Fix SQL quoting in grant macros to ensure role and privilege names are emitted as single-quoted string literals and bump the package version to 1.0.8.
Bug Fixes:
Enhancements:
Documentation: