Skip to content

Commit

Permalink
[Bug] Initialize sqlparse lexer prior to using sqlparse (#711) (#712)
Browse files Browse the repository at this point in the history
* changelog

* initialize sqlparse Lexer prior to using sqlparse

(cherry picked from commit d9274de)

Co-authored-by: Mike Alfare <[email protected]>
  • Loading branch information
github-actions[bot] and mikealfare authored Feb 6, 2024
1 parent 74de320 commit 0553b94
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20240206-132326.yaml
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 12 additions & 0 deletions dbt/adapters/redshift/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

0 comments on commit 0553b94

Please sign in to comment.