Skip to content

Commit

Permalink
Fix: serialization regression with sqlmesh.core.dialect.normalize_mod…
Browse files Browse the repository at this point in the history
…el_name (TobikoData#3025)

Co-authored-by: Toby Mao <[email protected]>
  • Loading branch information
z3z1ma and tobymao authored Aug 19, 2024
1 parent ab29085 commit bf1c6bc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion sqlmesh/utils/metaprogramming.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ def serialize_env(env: t.Dict[str, t.Any], path: Path) -> t.Dict[str, Executable

# We can't call getfile on built-in callables
# https://docs.python.org/3/library/inspect.html#inspect.getfile
file_path = Path(inspect.getfile(v)) if not inspect.isbuiltin(v) else None
file_path = (
Path(inspect.getfile(inspect.unwrap(v))) if not inspect.isbuiltin(v) else None
)

if _is_relative_to(file_path, path):
serialized[k] = Executable(
Expand Down
11 changes: 10 additions & 1 deletion tests/utils/test_metaprogramming.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sqlglot.expressions import to_table

import tests.utils.test_date as test_date
from sqlmesh.core.dialect import normalize_model_name
from sqlmesh.core import constants as c
from sqlmesh.utils.errors import SQLMeshError
from sqlmesh.utils.metaprogramming import (
Expand Down Expand Up @@ -42,7 +43,7 @@ def test_print_exception(mocker: MockerFixture):

expected_message = f"""Traceback (most recent call last):
File "{__file__}", line 39, in test_print_exception
File "{__file__}", line 40, in test_print_exception
eval("test_fun()", env)
File "<string>", line 1, in <module>
Expand Down Expand Up @@ -109,6 +110,7 @@ def main_func(y: int) -> int:
MyClass()
DataClass(x=y)
noop_metadata()
normalize_model_name("test")

def closure(z: int) -> int:
return z + Z
Expand All @@ -123,6 +125,7 @@ def test_func_globals() -> None:
"DataClass": DataClass,
"MyClass": MyClass,
"noop_metadata": noop_metadata,
"normalize_model_name": normalize_model_name,
"other_func": other_func,
"sqlglot": sqlglot,
}
Expand Down Expand Up @@ -155,6 +158,7 @@ def test_normalize_source() -> None:
MyClass()
DataClass(x=y)
noop_metadata()
normalize_model_name('test')
def closure(z: int):
return z + Z
Expand Down Expand Up @@ -195,6 +199,7 @@ def test_serialize_env() -> None:
MyClass()
DataClass(x=y)
noop_metadata()
normalize_model_name('test')
def closure(z: int):
return z + Z
Expand Down Expand Up @@ -252,6 +257,10 @@ def baz(self):
return None""",
is_metadata=True,
),
"normalize_model_name": Executable(
payload="from sqlmesh.core.dialect import normalize_model_name",
kind=ExecutableKind.IMPORT,
),
"other_func": Executable(
name="other_func",
path="test_metaprogramming.py",
Expand Down

0 comments on commit bf1c6bc

Please sign in to comment.