You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using imported decorators in SQLMesh models, the processing fails with AttributeError: 'Attribute' object has no attribute 'id'. Possible cause: SQLMesh's AST processing assumes all decorators are Name nodes, but they can also be Attribute nodes depending on the import style.
I created a test around it in test_metaprogramming.py for debugging:
def test_decorator_name_with_attribute():
@retry(stop=stop_after_attempt(3))
def fetch_data():
"""Test function with retry decorator"""
return "test data"
# The test should fail when trying to process this function's decorators
with pytest.raises(AttributeError, match="'Attribute' object has no attribute 'id'"):
decorators(fetch_data)
def test_decorator_in_sqlmesh_model():
# Mock the fetch_data function with retry decorator
@retry(stop=stop_after_attempt(3))
def fetch_data(url: str) -> str:
return "<xml>test data</xml>"
# Simplified version of your model
@model(
name='test.raw_data',
description='Test model with retry decorator',
kind=dict(name=ModelKindName.FULL),
columns={
"data": "text",
"_sqlmesh__extracted_at": "timestamp"
},
)
def execute(
context: ExecutionContext,
start: datetime,
end: datetime,
execution_time: datetime,
**kwargs: t.Any,
) -> pd.DataFrame:
# Use the decorated function
data = fetch_data("https://api.example.com")
return pd.DataFrame([{
"data": data,
"_sqlmesh__extracted_at": execution_time
}])
# Test that building the environment fails due to decorator
env: t.Dict[str, t.Any] = {}
with pytest.raises(AttributeError, match="'Attribute' object has no attribute 'id'"):
build_env(execute, env=env, name="TEST_MODEL", path=Path("test_metaprogramming.py"))
Description
When using imported decorators in SQLMesh models, the processing fails with
AttributeError: 'Attribute' object has no attribute 'id'
. Possible cause: SQLMesh's AST processing assumes all decorators areName
nodes, but they can also beAttribute
nodes depending on the import style.Reproduction
Environment
Steps
test_model.py
:Error
Expected Behavior
The model should process successfully, handling the
@retry
decorator.The text was updated successfully, but these errors were encountered: