sqlmesh
sqlmesh copied to clipboard
Should python macro functions work in audits?
In the example project, I added macros/constants.py containing
from sqlmesh import macro
from sqlmesh.core.macros import MacroEvaluator
@macro()
def min_item(
evaluator: MacroEvaluator
) -> int:
return 0
I modified models/incremental_model.sql to reference it like this:
...
WHERE
event_date BETWEEN @start_date AND @end_date
and item_id > @min_item()
which works just fine. But if I also modify audits/assert_positive_order_ids.sql to reference it:
...
SELECT
*
FROM @this_model
WHERE
item_id < @min_item()
then it fails to find the macro:
sqlmesh-example % sqlmesh audit
Error: Macro 'min_item' does not exist.
sqlmesh-example % sqlmesh --version
0.113.0
I believe we don't scan audits for macro references when constructing the model's python environment. This is why the macro can't be found.
@georgesittas , @Themiscodes can either of you please have a look when you get a chance.
Sure, I will look into it