Skip to content

Commit 262c3df

Browse files
committed
Fix: metadata status should not overwrite non-metadata status of used macro
1 parent fc7fe1b commit 262c3df

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

sqlmesh/core/model/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def make_python_env(
7474
# If this macro has been seen before as a non-metadata macro, prioritize that
7575
used_macros[name] = (
7676
macros[name],
77-
used_macros.get(name, (None, is_metadata))[1],
77+
used_macros.get(name, (None, is_metadata))[1] and is_metadata,
7878
)
7979
if name == c.VAR:
8080
args = macro_func_or_var.this.expressions
@@ -92,7 +92,7 @@ def make_python_env(
9292
# If this macro has been seen before as a non-metadata macro, prioritize that
9393
used_macros[name] = (
9494
macros[name],
95-
used_macros.get(name, (None, is_metadata))[1],
95+
used_macros.get(name, (None, is_metadata))[1] and is_metadata,
9696
)
9797
elif name in variables:
9898
used_variables.add(name)

tests/core/test_model.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8824,6 +8824,9 @@ def test_macros_referenced_in_metadata_statements_and_properties_are_metadata_on
88248824
non_zero_c1,
88258825
unique_values(columns := @m2()),
88268826
),
8827+
physical_properties (
8828+
random_prop = @random_prop_macro()
8829+
),
88278830
);
88288831
88298832
SELECT
@@ -8836,6 +8839,7 @@ def test_macros_referenced_in_metadata_statements_and_properties_are_metadata_on
88368839
ON_VIRTUAL_UPDATE_BEGIN;
88378840
88388841
@bla();
8842+
@random_prop_macro();
88398843
88408844
ON_VIRTUAL_UPDATE_END;
88418845
@@ -8879,6 +8883,10 @@ def zero_metadata(evaluator):
88798883
88808884
@macro()
88818885
def non_metadata_macro(evaluator):
8886+
return 1
8887+
8888+
@macro()
8889+
def random_prop_macro(evaluator):
88828890
return 1"""
88838891

88848892
test_macros = tmp_path / "macros/test_macros.py"
@@ -8927,7 +8935,7 @@ def test_signal_always_true(batch, arg1, arg2):
89278935

89288936
python_env = model.python_env
89298937

8930-
assert len(python_env) == 12
8938+
assert len(python_env) == 13
89318939
assert (python_env.get("test_signal_always_true") or empty_executable).is_metadata
89328940
assert (python_env.get("bar") or empty_executable).is_metadata
89338941
assert (python_env.get("m1") or empty_executable).is_metadata
@@ -8945,6 +8953,7 @@ def test_signal_always_true(batch, arg1, arg2):
89458953
# is true for zero_alt, which is referenced in the non_zero_c1 audit.
89468954
assert not (python_env.get("zero_alt") or empty_executable).is_metadata
89478955
assert not (python_env.get("non_metadata_macro") or empty_executable).is_metadata
8956+
assert not (python_env.get("random_prop_macro") or empty_executable).is_metadata
89488957

89498958

89508959
def test_scd_type_2_full_history_restatement():

0 commit comments

Comments
 (0)