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

[Bug] If a role doesn't have access to target.warehouse, when resetting the warehouse back to the initial warehouse because the snowflake_warehouse config is used, we emit a use warehouse None which errors #928

Open
3 of 11 tasks
jeremyyeo opened this issue Mar 21, 2025 · 0 comments
Labels
pkg:dbt-snowflake Issue affects dbt-snowflake type:bug Something isn't working as documented

Comments

@jeremyyeo
Copy link
Contributor

jeremyyeo commented Mar 21, 2025

Is this a new bug?

  • I believe this is a new bug
  • I have searched the existing issues, and I could not find an existing issue for this bug

Which packages are affected?

  • dbt-adapters
  • dbt-tests-adapter
  • dbt-athena
  • dbt-athena-community
  • dbt-bigquery
  • dbt-postgres
  • dbt-redshift
  • dbt-snowflake
  • dbt-spark

Current Behavior

When the default warehouse (target.warehouse) is not available to the user/role OR does not exist, dbt emits a use warehouse None when it switches back to the default warehouse (for models that use the snowflake_warehouse config.

Expected Behavior

At minimum, we should emit use warehouse {{ target.warehouse }} instead of the current behaviour.

Steps To Reproduce

  1. Create a warehouse but don't grant the role we're going to use permissions to the warehouse:
use role accountadmin;
create warehouse transformer_cant_use with warehouse_size = xsmall;
  1. Setup our Snowflake profile with the transformer role:
# ~/.dbt/profiles.yml
sf:
  target: default
  outputs:
    default:
      type: snowflake
      role: transformer
      warehouse: transformer_cant_use
      ...
  1. Setup our dbt project:
# dbt_project.yml
name: my_dbt_project
profile: sf
version: "1.0.0"
config-version: 2

models:
  my_dbt_project:
    +materialized: table
-- models/foo.sql
{{ config(snowflake_warehouse='analytics') }}
select 1 id

^ Make sure to use a snowflake_warehouse config that the role transformer can actually use.

  1. Build:
$ $ dbt --debug build

01:10:34  1 of 1 START sql table model sch.foo ........................................... [RUN]
01:10:34  Re-using an available connection from the pool (formerly list_db_sch, now model.my_dbt_project.foo)
01:10:34  Began compiling node model.my_dbt_project.foo
01:10:34  Writing injected SQL for node "model.my_dbt_project.foo"
01:10:34  Began executing node model.my_dbt_project.foo
01:10:34  Using snowflake connection "model.my_dbt_project.foo"
01:10:34  On model.my_dbt_project.foo: /* {"app": "dbt", "dbt_version": "1.9.3", "profile_name": "sf", "target_name": "ci", "node_id": "model.my_dbt_project.foo"} */
select current_warehouse() as warehouse
01:10:34  SQL status: SUCCESS 1 in 0.345 seconds
01:10:34  Using snowflake connection "model.my_dbt_project.foo"
01:10:34  On model.my_dbt_project.foo: /* {"app": "dbt", "dbt_version": "1.9.3", "profile_name": "sf", "target_name": "ci", "node_id": "model.my_dbt_project.foo"} */
use warehouse analytics
01:10:35  SQL status: SUCCESS 1 in 0.373 seconds
01:10:35  Writing runtime sql for node "model.my_dbt_project.foo"
01:10:35  Using snowflake connection "model.my_dbt_project.foo"
01:10:35  On model.my_dbt_project.foo: /* {"app": "dbt", "dbt_version": "1.9.3", "profile_name": "sf", "target_name": "ci", "node_id": "model.my_dbt_project.foo"} */
create or replace transient table db.sch.foo
         as
        (
select 1 id
        );
01:10:36  SQL status: SUCCESS 1 in 1.505 seconds
01:10:36  Using snowflake connection "model.my_dbt_project.foo"
01:10:36  On model.my_dbt_project.foo: /* {"app": "dbt", "dbt_version": "1.9.3", "profile_name": "sf", "target_name": "ci", "node_id": "model.my_dbt_project.foo"} */
use warehouse None
01:10:37  Snowflake adapter: Snowflake query id: 01bb2546-0807-d2fa-000d-378346de0cb6
01:10:37  Snowflake adapter: Snowflake error: 002043 (02000): SQL compilation error:
Object does not exist, or operation cannot be performed.
01:10:37  Database Error in model foo (models/foo.sql)
  002043 (02000): SQL compilation error:
  Object does not exist, or operation cannot be performed.
  compiled code at target/run/my_dbt_project/models/foo.sql
01:10:37  Sending event: {'category': 'dbt', 'action': 'run_model', 'label': '530318a4-7938-42c9-b7a2-57a00a2f6dc8', 'context': [<snowplow_tracker.self_describing_json.SelfDescribingJson object at 0x1081a0310>]}
01:10:37  1 of 1 ERROR creating sql table model sch.foo .................................. [ERROR in 2.73s]

  1. We ran a select current_warehouse() as warehouse to check what the current one is - however, it looks like if you don't have access to it - the result is None.
  2. Because None != 'analytics' - we then call use warehouse analytics.
  3. We build our model.
  4. We reset back to the warehouse back in (1) - which of course is None.

Relevant log output

see above

Environment

- OS: macOS
- Python: 3.11.9
- dbt-core: 1.9.3
- dbt-adapters: 1.13.0
- dbt-snowflake: 1.9.2

Additional Context

Checking the output of current_warehouse() when warehouse is not available to role:

# check.py
import snowflake.connector
print(snowflake.connector.__version__)

# Gets the version
ctx = snowflake.connector.connect(
    user='...',
    password='...',
    account='...',
    warehouse='transformer_cant_use',
    role='transformer'
    )
cs = ctx.cursor()
try:
    cs.execute("SELECT current_warehouse() as c")
    one_row = cs.fetchone()
    print(one_row[0])
finally:
    cs.close()
ctx.close()
$ python check.py
3.14.0
None

Note: None is also returned if the warehouse doesn't exist.

@jeremyyeo jeremyyeo added triage:product In Product's queue type:bug Something isn't working as documented labels Mar 21, 2025
@amychen1776 amychen1776 added pkg:dbt-snowflake Issue affects dbt-snowflake and removed triage:product In Product's queue labels Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:dbt-snowflake Issue affects dbt-snowflake type:bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

2 participants