diff --git a/.changes/unreleased/Fixes-20240206-132326.yaml b/.changes/unreleased/Fixes-20240206-132326.yaml new file mode 100644 index 000000000..45b3a74c8 --- /dev/null +++ b/.changes/unreleased/Fixes-20240206-132326.yaml @@ -0,0 +1,7 @@ +kind: Fixes +body: Initialize sqlparse.Lexer to resolve issue with `dbt docs generate` that includes + external tables +time: 2024-02-06T13:23:26.061133-05:00 +custom: + Author: mikealfare + Issue: "710" diff --git a/dbt/adapters/redshift/connections.py b/dbt/adapters/redshift/connections.py index 7d05a3395..24c5aa1a5 100644 --- a/dbt/adapters/redshift/connections.py +++ b/dbt/adapters/redshift/connections.py @@ -350,6 +350,7 @@ def add_query(self, sql, auto_begin=True, bindings=None, abridge_sql_log=False): connection = None cursor = None + self._initialize_sqlparse_lexer() queries = sqlparse.split(sql) for query in queries: @@ -381,3 +382,14 @@ def get_credentials(cls, credentials): @classmethod def data_type_code_to_name(cls, type_code: Union[int, str]) -> str: return get_datatype_name(type_code) + + @staticmethod + def _initialize_sqlparse_lexer(): + """ + Resolves: https://github.com/dbt-labs/dbt-redshift/issues/710 + Implementation of this fix: https://github.com/dbt-labs/dbt-core/pull/8215 + """ + from sqlparse.lexer import Lexer # type: ignore + + if hasattr(Lexer, "get_default_instance"): + Lexer.get_default_instance()