dbt-labs / dbt-labs/dbt-adapters

[Bug] Using `grants` on `materialized_view` raises an error

Open
#558 1 comment 0 reactions 0 assignees View on GitHub
feature:materialized-views pkg:dbt-bigquery type:bug
Dominant language
Python
Stars
233
Forks
362
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### Is this a new bug in dbt-bigquery?

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

### Current Behavior

When using the `grants` configuration on a materialized view, the generated grant/revoke statement results in:

```sql
grant on materialized_view to "",""
```

and respectively:
```sql
revoke on materialized_view from "",""
```

This results in an error because BigQuery expect the relation type to be `materialized view` instead of `materialized_view`.

[See documentation](https://cloud.google.com/bigquery/docs/control-access-to-resources-iam#grant_access_to_a_table_or_view)

### Expected Behavior

The grant/revoke statements execute successfully.

### Steps To Reproduce

1. Create a models like the following:

`base_table.sql`:
```sql
{{
config(
materialized='table'
)
}}
SELECT 1 AS test
```

`grants_materialized_view.sql`:
```sql
{{
config(
materialized='materialized_view',
grants={
"roles/bigquery.dataViewer": ["user:user@example.tld"]
}
)
}}
SELECT * FROM {{ ref('base_table') }}
```

2. Create the models using `dbt run`

3. Models should be created and the described privileges granted but the following error occurs:

```
Database Error in model grants_materialized_view (models/grants_materialized_view.sql)
Invalid object type for GRANT statement: materialized_view at [6:5]
compiled Code at /grants_materialized_view.sql
```

### Relevant log output

```shell
Database Error in model grants_materialized_view (models/grants_materialized_view.sql)
Invalid object type for GRANT statement: materialized_view at [6:5]
compiled Code at /grants_materialized_view.sql
```

### Environment

```markdown
- OS: MacOS
- Python: 3.12
- dbt-core: 1.8.1
- dbt-bigquery: 1.8.1
```

### Additional Context

Proposed fix: https://github.com/dbt-labs/dbt-bigquery/pull/1267

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.