Skip to content

Commit

Permalink
[CT-1661] Quotes usernames with special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
qmg-karan committed Jul 19, 2024
1 parent e3465c2 commit 22f399b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
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

0 comments on commit 22f399b

Please sign in to comment.