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-1661] Quotes usernames with special characters #265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20240719-155743.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Quotes database users that contain special characters
time: 2024-07-19T15:57:43.697763+01:00
custom:
Author: qmg-karan ChocoletMousse
Issue: "156"
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ Unit tests can be run locally without setting up a database connection:
# Note: replace $strings with valid names

# run all unit tests
hatch run unit-test
hatch run unit-tests

# run all unit tests in a module
hatch run unit-test tests/unit/$test_file_name.py
hatch run unit-tests tests/unit/$test_file_name.py

# run a specific unit test
hatch run unit-test tests/unit/$test_file_name.py::$test_class_name::$test_method_name
hatch run unit-tests tests/unit/$test_file_name.py::$test_class_name::$test_method_name
```

### Testing against a development branch
Expand Down
17 changes: 15 additions & 2 deletions dbt/include/global_project/macros/adapters/apply_grants.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,21 @@
show grants on {{ relation.render() }}
{% endmacro %}

{% macro quote_grantees(grantees) %}
{%- set quoted_grantees = [] -%}
{%- for grantee in grantees -%}
{%- if (('@' in grantee) or ('-' in grantee) or ('.' in grantee)) -%}
{%- do quoted_grantees.append(adapter.quote(grantee)) -%}
{%- else -%}
{%- do quoted_grantees.append(grantee) -%}
{%- endif -%}
{%- endfor -%}
{%- do return quoted_grantees -%}
{% endmacro %}

{% macro get_grant_sql(relation, privilege, grantees) %}
{{ return(adapter.dispatch('get_grant_sql', 'dbt')(relation, privilege, grantees)) }}
{%- set updated_grantees = quote_grantees(grantees) -%}
{{ return(adapter.dispatch('get_grant_sql', 'dbt')(relation, privilege, updated_grantees)) }}
{% endmacro %}

{%- macro default__get_grant_sql(relation, privilege, grantees) -%}
Expand All @@ -75,7 +87,8 @@


{% macro get_revoke_sql(relation, privilege, grantees) %}
{{ return(adapter.dispatch('get_revoke_sql', 'dbt')(relation, privilege, grantees)) }}
{%- set updated_grantees = quote_grantees(grantees) -%}
{{ return(adapter.dispatch('get_revoke_sql', 'dbt')(relation, privilege, updated_grantees)) }}
{% endmacro %}

{%- macro default__get_revoke_sql(relation, privilege, grantees) -%}
Expand Down