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] Materialized views cannot be authorized #773

Open
2 tasks done
kubikb opened this issue Feb 3, 2025 · 0 comments · May be fixed by #788
Open
2 tasks done

[Bug] Materialized views cannot be authorized #773

kubikb opened this issue Feb 3, 2025 · 0 comments · May be fixed by #788
Labels
feature:materialized-views Issues related to materialized views pkg:dbt-bigquery Issue affects dbt-bigquery type:bug Something isn't working as documented

Comments

@kubikb
Copy link

kubikb commented Feb 3, 2025

Is this a new bug in dbt-bigquery?

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

Current Behavior

Similarly to BigQuery views, BigQuery materialized views can also be authorized to access the data in another dataset(s). However, providing the grant_access_to configuration to a model with materialized_view materialization goes silently ignored and the materialized view does NOT get authorized to access data in another dataset. With models with view materialization, the grant_access_to configuration leads to the desired behavior, namely the view gets authorized to access data in another dataset.

Expected Behavior

As per the dbt official documentation, the grant_access_to config can be used to "grant the view model access to select from the list of datasets provided". Similarly, one would expect dbt models with materialization set to materialized_view take the grant_access_to config and be authorized to access data in another dataset.

Steps To Reproduce

  1. Create a new or use an existing dbt project. The dbt_project.yml contents I used:

# Name your project! Project names should contain only lowercase characters
# and underscores. A good package name should reflect your organization's
# name or the intended use of these models
name: 'materialized_view__grant'
version: '1.0.0'

# This setting configures which "profile" dbt uses for this project.
profile: 'materialized_view__grant'

# These configurations specify where dbt should look for different types of files.
# The `model-paths` config, for example, states that models in this project can be
# found in the "models/" directory. You probably won't need to change these!
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]

clean-targets:         # directories to be removed by `dbt clean`
  - "target"
  - "dbt_packages"


# Configuring models
# Full documentation: https://docs.getdbt.com/docs/configuring-models

# In this example config, we tell dbt to build all models in the example/
# directory as views. These settings can be overridden in the individual model
# files using the `{{ config(...) }}` macro.
models:
  materialized_view__grant:
    # Config indicated by + and applies to all files under models/example/
    example:
  1. Create a test table, materialized view, and view.

test_model.sql contents:

{{ config(materialized='table') }}

with source_data as (

    select 1 as id
    union all
    select null as id

)

select *
from source_data

test_materialized_view.sql contents:

{{ config(
    materialized='materialized_view',
    grant_access_to=[
      {'project': '{ANOTHER_PROJECT_ID}', 'dataset': 'test_dataset'},
    ]
) }}

select
    id,
    count(1) AS count
from {{ ref('test_model') }}
group by id

test_view.sql contents:

{{ config(
    materialized='view',
    grant_access_to=[
      {'project': '{ANOTHER_PROJECT_ID}', 'dataset': 'test_dataset'},
    ]
) }}

select
    id,
    count(1) AS count
from {{ ref('test_model') }}
group by id
  1. Execute dbt run.
  2. The test_view becomes an authorized view, while test_materialized_view gets ignored and does not get authorized to access data in dataset {ANOTHER_PROJECT_ID}.test_dataset.
Image

Relevant log output

(env) balintkubik@Mac materialized_view__grant % dbt run         
07:10:14  Running with dbt=1.9.2
07:10:15  Registered adapter: bigquery=1.9.1
07:10:15  Unable to do partial parsing because a project config has changed
07:10:15  Found 3 models, 489 macros
07:10:15  
07:10:15  Concurrency: 1 threads (target='dev')
07:10:15  
07:10:17  1 of 3 START sql table model dbt.test_model .................................... [RUN]
07:10:24  1 of 3 OK created sql table model dbt.test_model ............................... [CREATE TABLE (2.0 rows, 0 processed) in 7.14s]
07:10:24  2 of 3 START sql materialized_view model dbt.test_materialized_view ............ [RUN]
07:10:27  2 of 3 OK created sql materialized_view model dbt.test_materialized_view ....... [None (0 processed) in 2.06s]
07:10:27  3 of 3 START sql view model dbt.test_view ...................................... [RUN]
07:10:30  3 of 3 OK created sql view model dbt.test_view ................................. [CREATE VIEW (0 processed) in 3.00s]
07:10:30  
07:10:30  Finished running 1 materialized view model, 1 table model, 1 view model in 0 hours 0 minutes and 14.07 seconds (14.07s).
07:10:30  
07:10:30  Completed successfully
07:10:30  
07:10:30  Done. PASS=3 WARN=0 ERROR=0 SKIP=0 TOTAL=3

Environment

- OS: MacOS 15.2 (24C101)
- Python: 3.12.5
- dbt-core: 1.9.2
- dbt-bigquery: 1.9.1

Additional Context

No response

@amychen1776 amychen1776 transferred this issue from dbt-labs/dbt-bigquery Feb 4, 2025
@kubikb kubikb linked a pull request Feb 5, 2025 that will close this issue
4 tasks
@amychen1776 amychen1776 added triage:product In Product's queue type:bug Something isn't working as documented feature:materialized-views Issues related to materialized views pkg:dbt-bigquery Issue affects dbt-bigquery and removed triage:product In Product's queue labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:materialized-views Issues related to materialized views pkg:dbt-bigquery Issue affects dbt-bigquery type:bug Something isn't working as documented
Projects
None yet
2 participants