Skip to content

Commit cd57592

Browse files
committed
Fix: ensure paths exist before treating them as relative (metaprogramming)
1 parent 780ebae commit cd57592

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

sqlmesh/utils/metaprogramming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _is_relative_to(path: t.Optional[Path | str], other: t.Optional[Path | str])
3737
if isinstance(other, str):
3838
other = Path(other)
3939

40-
if "site-packages" in str(path):
40+
if "site-packages" in str(path) or not path.exists() or not other.exists():
4141
return False
4242

4343
try:

tests/core/test_model.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10122,3 +10122,22 @@ def check_self_schema(evaluator):
1012210122

1012310123
context = Context(paths=tmp_path, config=config)
1012410124
context.plan(no_prompts=True, auto_apply=True)
10125+
10126+
10127+
def test_model_relies_on_os_getenv(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
10128+
init_example_project(tmp_path, dialect="duckdb", template=ProjectTemplate.EMPTY)
10129+
10130+
(tmp_path / "macros" / "getenv_macro.py").write_text(
10131+
"""
10132+
from os import getenv
10133+
from sqlmesh import macro
10134+
10135+
@macro()
10136+
def foo(evaluator):
10137+
getenv("foo", None)
10138+
return 1"""
10139+
)
10140+
(tmp_path / "models" / "model.sql").write_text("MODEL (name test); SELECT @foo() AS foo")
10141+
10142+
monkeypatch.chdir(tmp_path)
10143+
ctx = Context(paths=tmp_path)

0 commit comments

Comments
 (0)