Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,4 @@ banned-module-level-imports = [
"sqlmesh/lsp/**/*.py" = ["TID251"]
"tests/lsp/**/*.py" = ["TID251"]
"benchmarks/lsp*.py" = ["TID251"]
"sqlmesh/dbt/builtin.py" = ["T100"]
15 changes: 14 additions & 1 deletion sqlmesh/dbt/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from sqlmesh.dbt.relation import Policy
from sqlmesh.dbt.target import TARGET_TYPE_TO_CONFIG_CLASS
from sqlmesh.dbt.util import DBT_VERSION
from sqlmesh.utils import AttributeDict, yaml
from sqlmesh.utils import AttributeDict, debug_mode_enabled, yaml
from sqlmesh.utils.date import now
from sqlmesh.utils.errors import ConfigError, MacroEvalError
from sqlmesh.utils.jinja import JinjaMacroRegistry, MacroReference, MacroReturnVal
Expand Down Expand Up @@ -316,6 +316,15 @@ def _try_literal_eval(value: str) -> t.Any:
return value


def debug() -> str:
import sys
import ipdb # type: ignore

frame = sys._getframe(3)
ipdb.set_trace(frame)
return ""


BUILTIN_GLOBALS = {
"dbt_version": version.__version__,
"env_var": env_var,
Expand All @@ -336,6 +345,10 @@ def _try_literal_eval(value: str) -> t.Any:
"zip_strict": lambda *args: list(zip(*args)),
}

# Add debug function conditionally both with dbt or sqlmesh equivalent flag
if os.environ.get("DBT_MACRO_DEBUGGING") or debug_mode_enabled():
BUILTIN_GLOBALS["debug"] = debug
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does dbt do with a debug() call where DBT_MACRO_DEBUGGING is not set?

Does it just no-op, or does it throw an error? Because if it no-op's then wouldnt we need to always include it in the builtin globals and move the "is enabled?" check to within the implementation of debug()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the latter, they have it under a conditional as well so that it throws an error (maybe since they warn "Do not deploy code to production that uses the debug macro" to ensure this is only for debugging. This is why I wanted to exactly mirror their approach to get the same result.

so running dbt when the flag is not set you get an error it is undefined:

06:44:48  Encountered an error:
Compilation Error in operation jaffle_shop-on-run-end-0 (./dbt_project.yml)
  'debug' is undefined

and for sqlmesh you'd get similarly the undefined error:

Error: An error occurred during rendering of the 'after_all' statements:
Could not render or parse jinja at 'None'.
'debug' is undefined


BUILTIN_FILTERS = {
"as_bool": as_bool,
"as_native": _try_literal_eval,
Expand Down