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

snowflake__get_profile_creation_query does not work depending on environment #1328

Closed
pei0804 opened this issue Dec 13, 2023 · 2 comments
Closed
Labels
Bug Something isn't working Triage 👀

Comments

@pei0804
Copy link

pei0804 commented Dec 13, 2023

Describe the bug
Errors occur when referencing multiple databases or Snowflake databases.

To Reproduce
Steps to reproduce the behavior:

  1. Create multiple databases and use them in dbt.
  2. Execute dbt run-operation create_elementary_user

Expected behavior
Generated SQL can be executed.

Additional context

SQL that is actually generated and causes problems

-- Information schema access
CREATE OR REPLACE PROCEDURE ELEMENTARY_GRANT_INFO_SCHEMA_ACCESS(database_name STRING, role_name STRING)
  RETURNS VARCHAR
  LANGUAGE SQL
  AS
  $$
    BEGIN
      GRANT USAGE,MONITOR ON DATABASE IDENTIFIER(:database_name) TO ROLE IDENTIFIER(:role_name);
      GRANT USAGE,MONITOR ON ALL SCHEMAS IN DATABASE PREP TO ROLE IDENTIFIER(:role_name);
      GRANT USAGE,MONITOR ON FUTURE SCHEMAS IN DATABASE PREP TO ROLE identifier(:role_name);

      GRANT REFERENCES ON ALL TABLES IN DATABASE IDENTIFIER(:database_name) TO ROLE IDENTIFIER(:role_name);
      GRANT REFERENCES ON ALL VIEWS IN DATABASE IDENTIFIER(:database_name) TO ROLE IDENTIFIER(:role_name);
      GRANT REFERENCES ON ALL EXTERNAL TABLES IN DATABASE IDENTIFIER(:database_name) TO ROLE IDENTIFIER(:role_name);

      GRANT REFERENCES ON FUTURE TABLES IN DATABASE IDENTIFIER(:database_name) TO ROLE IDENTIFIER(:role_name);
      GRANT REFERENCES ON FUTURE VIEWS IN DATABASE IDENTIFIER(:database_name) TO ROLE IDENTIFIER(:role_name);
      GRANT REFERENCES ON FUTURE EXTERNAL TABLES IN DATABASE IDENTIFIER(:database_name) TO ROLE IDENTIFIER(:role_name);
    END;
  $$
;
CALL ELEMENTARY_GRANT_INFO_SCHEMA_ACCESS('snowflake', $elementary_role);
CALL ELEMENTARY_GRANT_INFO_SCHEMA_ACCESS('RAW', $elementary_role);
CALL ELEMENTARY_GRANT_INFO_SCHEMA_ACCESS('ELEMENTARY', $elementary_role);
CALL ELEMENTARY_GRANT_INFO_SCHEMA_ACCESS('PROD', $elementary_role);
CALL ELEMENTARY_GRANT_INFO_SCHEMA_ACCESS('PREP', $elementary_role);

Want

  • The snowflake database is a special database, so if you try to grant it, you will get an error, which you want to ignore.
  • In an environment where multiple databases are being operated, grant to {{database}} will be insufficient, so we want to use the database of the argument.
@pei0804 pei0804 added Bug Something isn't working Triage 👀 labels Dec 13, 2023
@haritamar
Copy link
Collaborator

Closing issue since it was fixed in a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Triage 👀
Projects
None yet
Development

No branches or pull requests

2 participants