Skip to content

Commit bff4d90

Browse files
Feat(dbt): Add dbt debug macro
1 parent 40fb9b6 commit bff4d90

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,4 @@ banned-module-level-imports = [
301301
"sqlmesh/lsp/**/*.py" = ["TID251"]
302302
"tests/lsp/**/*.py" = ["TID251"]
303303
"benchmarks/lsp*.py" = ["TID251"]
304+
"sqlmesh/dbt/builtin.py" = ["T100"]

sqlmesh/dbt/builtin.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from sqlmesh.dbt.relation import Policy
2222
from sqlmesh.dbt.target import TARGET_TYPE_TO_CONFIG_CLASS
2323
from sqlmesh.dbt.util import DBT_VERSION
24-
from sqlmesh.utils import AttributeDict, yaml
24+
from sqlmesh.utils import AttributeDict, debug_mode_enabled, yaml
2525
from sqlmesh.utils.date import now
2626
from sqlmesh.utils.errors import ConfigError, MacroEvalError
2727
from sqlmesh.utils.jinja import JinjaMacroRegistry, MacroReference, MacroReturnVal
@@ -316,6 +316,15 @@ def _try_literal_eval(value: str) -> t.Any:
316316
return value
317317

318318

319+
def debug() -> str:
320+
import sys
321+
import ipdb # type: ignore
322+
323+
frame = sys._getframe(3)
324+
ipdb.set_trace(frame)
325+
return ""
326+
327+
319328
BUILTIN_GLOBALS = {
320329
"dbt_version": version.__version__,
321330
"env_var": env_var,
@@ -336,6 +345,10 @@ def _try_literal_eval(value: str) -> t.Any:
336345
"zip_strict": lambda *args: list(zip(*args)),
337346
}
338347

348+
# Add debug function conditionally both with dbt or sqlmesh equivalent flag
349+
if os.environ.get("DBT_MACRO_DEBUGGING") or debug_mode_enabled():
350+
BUILTIN_GLOBALS["debug"] = debug
351+
339352
BUILTIN_FILTERS = {
340353
"as_bool": as_bool,
341354
"as_native": _try_literal_eval,

0 commit comments

Comments
 (0)