Skip to content

Commit 3788630

Browse files
Feat(dbt): Add dbt debug macro
1 parent 0c2ba86 commit 3788630

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
@@ -20,7 +20,7 @@
2020
from sqlmesh.dbt.relation import Policy
2121
from sqlmesh.dbt.target import TARGET_TYPE_TO_CONFIG_CLASS
2222
from sqlmesh.dbt.util import DBT_VERSION
23-
from sqlmesh.utils import AttributeDict, yaml
23+
from sqlmesh.utils import AttributeDict, debug_mode_enabled, yaml
2424
from sqlmesh.utils.date import now
2525
from sqlmesh.utils.errors import ConfigError, MacroEvalError
2626
from sqlmesh.utils.jinja import JinjaMacroRegistry, MacroReference, MacroReturnVal
@@ -309,6 +309,15 @@ def _try_literal_eval(value: str) -> t.Any:
309309
return value
310310

311311

312+
def debug() -> str:
313+
import sys
314+
import ipdb # type: ignore
315+
316+
frame = sys._getframe(3)
317+
ipdb.set_trace(frame)
318+
return ""
319+
320+
312321
BUILTIN_GLOBALS = {
313322
"dbt_version": version.__version__,
314323
"env_var": env_var,
@@ -329,6 +338,10 @@ def _try_literal_eval(value: str) -> t.Any:
329338
"zip_strict": lambda *args: list(zip(*args)),
330339
}
331340

341+
# Add debug function conditionally both with dbt or sqlmesh equivalent flag
342+
if os.environ.get("DBT_MACRO_DEBUGGING") or debug_mode_enabled():
343+
BUILTIN_GLOBALS["debug"] = debug
344+
332345
BUILTIN_FILTERS = {
333346
"as_bool": as_bool,
334347
"as_native": _try_literal_eval,

0 commit comments

Comments
 (0)