Skip to content

Commit bf1c6bc

Browse files
z3z1matobymao
andauthored
Fix: serialization regression with sqlmesh.core.dialect.normalize_model_name (#3025)
Co-authored-by: Toby Mao <toby.mao@gmail.com>
1 parent ab29085 commit bf1c6bc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

sqlmesh/utils/metaprogramming.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ def serialize_env(env: t.Dict[str, t.Any], path: Path) -> t.Dict[str, Executable
351351

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

356358
if _is_relative_to(file_path, path):
357359
serialized[k] = Executable(

tests/utils/test_metaprogramming.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sqlglot.expressions import to_table
1010

1111
import tests.utils.test_date as test_date
12+
from sqlmesh.core.dialect import normalize_model_name
1213
from sqlmesh.core import constants as c
1314
from sqlmesh.utils.errors import SQLMeshError
1415
from sqlmesh.utils.metaprogramming import (
@@ -42,7 +43,7 @@ def test_print_exception(mocker: MockerFixture):
4243

4344
expected_message = f"""Traceback (most recent call last):
4445
45-
File "{__file__}", line 39, in test_print_exception
46+
File "{__file__}", line 40, in test_print_exception
4647
eval("test_fun()", env)
4748
4849
File "<string>", line 1, in <module>
@@ -109,6 +110,7 @@ def main_func(y: int) -> int:
109110
MyClass()
110111
DataClass(x=y)
111112
noop_metadata()
113+
normalize_model_name("test")
112114

113115
def closure(z: int) -> int:
114116
return z + Z
@@ -123,6 +125,7 @@ def test_func_globals() -> None:
123125
"DataClass": DataClass,
124126
"MyClass": MyClass,
125127
"noop_metadata": noop_metadata,
128+
"normalize_model_name": normalize_model_name,
126129
"other_func": other_func,
127130
"sqlglot": sqlglot,
128131
}
@@ -155,6 +158,7 @@ def test_normalize_source() -> None:
155158
MyClass()
156159
DataClass(x=y)
157160
noop_metadata()
161+
normalize_model_name('test')
158162
159163
def closure(z: int):
160164
return z + Z
@@ -195,6 +199,7 @@ def test_serialize_env() -> None:
195199
MyClass()
196200
DataClass(x=y)
197201
noop_metadata()
202+
normalize_model_name('test')
198203
199204
def closure(z: int):
200205
return z + Z
@@ -252,6 +257,10 @@ def baz(self):
252257
return None""",
253258
is_metadata=True,
254259
),
260+
"normalize_model_name": Executable(
261+
payload="from sqlmesh.core.dialect import normalize_model_name",
262+
kind=ExecutableKind.IMPORT,
263+
),
255264
"other_func": Executable(
256265
name="other_func",
257266
path="test_metaprogramming.py",

0 commit comments

Comments
 (0)