Fix grant macros SQL quoting (v1.0.8)#36
Merged
Conversation
The Jinja tojson filter wraps values in double quotes which Snowflake interprets as identifiers causing invalid identifier errors. Replaced with the idiomatic join pattern to produce single-quoted SQL string literals. 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 updated grant_schema_read macro SQL generationsequenceDiagram
actor User
participant dbt
participant grant_schema_read
participant Snowflake
User->>dbt: dbt run-operation grant_schema_read
dbt->>grant_schema_read: render macro
grant_schema_read->>grant_schema_read: build revoke_query using grant_roles | join("', '")
grant_schema_read->>dbt: return revoke_query SQL
dbt->>Snowflake: run_query(revoke_query)
Snowflake-->>dbt: execute SQL (grantee not in ('ROLE_A', 'ROLE_B')) without invalid identifier
dbt-->>User: operation completes successfully
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:
- The new
'{{ list | join("', '") }}'pattern will break if any privilege or role name contains a single quote; consider adding an escaping step or using a helper that safely quotes identifiers/literals for Snowflake. - You might want to centralize the SQL literal-joining logic (for privileges/roles) in a small helper macro so the quoting pattern is enforced consistently and easier to adjust if Snowflake or dbt behavior changes again.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `'{{ list | join("', '") }}'` pattern will break if any privilege or role name contains a single quote; consider adding an escaping step or using a helper that safely quotes identifiers/literals for Snowflake.
- You might want to centralize the SQL literal-joining logic (for privileges/roles) in a small helper macro so the quoting pattern is enforced consistently and easier to adjust if Snowflake or dbt behavior changes again.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') | join(', ')with the idiomatic'{{ list | join("', '") }}'pattern 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 prevent Snowflake from treating role and privilege names as identifiers, and bump the package version to 1.0.8.
Bug Fixes:
Enhancements:
Build:
Documentation: