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

[CT-1598] [Regression] Granting select does not work with dbt-postgres==1.3.1 #6378

Closed
2 tasks done
keurcien opened this issue Dec 5, 2022 · 4 comments
Closed
2 tasks done
Labels
bug Something isn't working postgres Team:Adapters Issues designated for the adapter area of the code

Comments

@keurcien
Copy link

keurcien commented Dec 5, 2022

Is this a regression in a recent version of dbt-core?

  • I believe this is a regression in dbt-core functionality
  • I have searched the existing issues, and I could not find an existing issue for this regression

Current Behavior

Granting select to a certain user by adding this config to a model used to work with dbt 1.1.x, but after an upgrade to dbt 1.3.0, this raises an error when running dbt run --models xxx

# xxx.sql
{{ 
    config(
        grants = {'select': ['user_a']}
    )
}}

Expected/Previous Behavior

The dbt command should not fail.

Steps To Reproduce

  1. Use a postgres profile
  2. Create a dbt model one.sql
select 1
  1. Add the config
{{ 
    config(
        grants = {'select': ['user_a']}
    )
}}

4.Run the command dbt run --models one

Relevant log output

No response

Environment

- OS: macOS 13.0.1
- Python: python 3.10
- dbt (working version): 1.1.0
- dbt (regression version): 1.3.1

Which database adapter are you using with dbt?

postgres

Additional Context

No response

@keurcien keurcien added bug Something isn't working regression triage labels Dec 5, 2022
@github-actions github-actions bot changed the title [Regression] Granting select does not work with dbt-postgres==1.3.1 [CT-1598] [Regression] Granting select does not work with dbt-postgres==1.3.1 Dec 5, 2022
@jtcohen6
Copy link
Contributor

jtcohen6 commented Dec 5, 2022

@keurcien What's the actual error you're seeing?

Granting select to a certain user by adding this config to a model used to work with dbt 1.1.x, but after an upgrade to dbt 1.3.0, this raises an error when running dbt run --models xxx

This is surprising — we only added built-in support for grants in dbt-core v1.2.x, and we didn't make any significant changes from v1.2 → v1.3.

Is it possible that you hand-rolled your own implementation of a grants config? In that case, upgrading from v1.1 → v1.3 would mean that dbt's built-in grants implementation would start taking effect, and it could conflict with your own custom one.

@keurcien
Copy link
Author

keurcien commented Dec 6, 2022

Ok actually my user was not 'user_a' but 'metabase-proxy' and it might be due to the dash -. We did not have a custom implementation and I'm pretty sure we were under 1.1 and had it running, so this is strange.

{{ 
    config(
        grants = {'select': ['metabase-proxy']}
    )
}}
> dbt run --models one.sql

14:48:30  Running with dbt=1.3.1
14:48:30  Found 106 models, 1 test, 0 snapshots, 0 analyses, 733 macros, 0 operations, 3 seed files, 43 sources, 3 exposures, 0 metrics
14:48:30  
14:48:34  Concurrency: 4 threads (target='dev')
14:48:34  
14:48:34  1 of 1 START sql table model core.one .......................................... [RUN]
14:48:34  1 of 1 ERROR creating sql table model core.one ................................. [ERROR in 0.28s]
14:48:35  
14:48:35  Finished running 1 table model in 0 hours 0 minutes and 4.22 seconds (4.22s).
14:48:35  
14:48:35  Completed with 1 error and 0 warnings:
14:48:35  
14:48:35  Database Error in model one (models/marts/core/one.sql)
14:48:35    syntax error at or near "-"
14:48:35    LINE 4: ...    grant select on "dwh"."core"."one" to metabase-proxy

@jtcohen6
Copy link
Contributor

jtcohen6 commented Dec 6, 2022

Ah! So either we need to add quotes to the grantees here, similar to what we do on dbt-bigquery:

{%- macro default__get_grant_sql(relation, privilege, grantees) -%}
grant {{ privilege }} on {{ relation }} to {{ grantees | join(', ') }}
{%- endmacro -%}

Or you need to add (double) quotes in your own config:

{{ 
    config(
        grants = {'select': ['"metabase-proxy"']}
    )
}}

There isn't usually a downside to quoting on Postgres/Redshift, but worth considering edge cases.

I still don't see how this is a regression in v1.3, though.

@jtcohen6 jtcohen6 added Team:Adapters Issues designated for the adapter area of the code and removed triage regression labels Dec 6, 2022
@keurcien
Copy link
Author

keurcien commented Dec 6, 2022

Oh ok! Yeah my bad because I thought it was broken, gonna close the issue. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgres Team:Adapters Issues designated for the adapter area of the code
Projects
None yet
Development

No branches or pull requests

2 participants