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
{{ message }}
Repository navigation
Audits on kind EMBEDDED models fail with NotFound error during sqlmesh plan #5546
Models defined with kind EMBEDDED are purely virtual and are designed to be in-lined as CTEs into downstream models. They should never be materialized into a physical table.
When an EMBEDDED model includes an audits block (as is currently permitted), the sqlmesh plan command fails because it attempts to execute the audit query against a non-existent physical table, resulting in a 404 Not found error in the database engine (this behavior has been confirmed on BigQuery).
Audits should either be explicitly forbidden on EMBEDDED models during project validation, or they should be silently ignored/omitted during plan generation for this specific model kind.
Minimum Viable Example
Create the model definition: models/broken_embedded_model.sql
MODEL (
name my_project.virtual_source,
kind EMBEDDED,
columns (
id INT,
value STRING
),
audits (
not_null(columns := (id)),
unique_combination_of_columns(columns := (id))
)
);
-- Minimal dummy SQL that should be inlinedSELECT
CAST(1ASINT) AS id,
'A'AS value
UNION ALLSELECT
CAST(2ASINT) AS id,
'B'AS value;
Run the plan command:
sqlmesh plan
Expected Behavior
Preferred: The CLI should fail project validation immediately upon load with a clear error: "Audits are not permitted on models with kind EMBEDDED."
Alternative: The planner should recognize the EMBEDDED kind and omit/skip the audit step for this model during the plan generation.
Actual Behavior
The sqlmesh plan fails with a NotFound error because it attempts to query a materialized table proxy for the virtual model to execute the audit:
"my_project"."virtual_source"
NotFound:
404 Not found: Table <project-id>:<schema-physical>.my_project__virtual_source__<hash> was not found in location US; reason: notFound, message: Not found: Table <project-id>:<schema-physical>.my_project__virtual_source__<hash> was not found in location US
I'd like to work on this issue. Based on the discussion, my understanding is that we should add validation to reject audits on EMBEDDED models during model definition parsing, since EMBEDDED models are virtual and never materialize.
My proposed approach:
Add validation in _Model.validate_definition() to check if kind == EMBEDDED and audits is not empty
Raise a ConfigError with a clear error message explaining why audits aren't supported
Add test coverage in tests/core/test_model.py to verify the validation works
Does this sound good? Happy to submit a PR with this fix!
Activity
izeigerman commentedon Oct 23, 2025
I agree that audits should be explicitly forbidden for embedded models since models of this kind are not part of the evaluation DAG.
bearInTheRoad commentedon Nov 2, 2025
Hi @izeigerman and team! 👋
I'd like to work on this issue. Based on the discussion, my understanding is that we should add validation to reject audits on EMBEDDED models during model definition parsing, since EMBEDDED models are virtual and never materialize.
My proposed approach:
Does this sound good? Happy to submit a PR with this fix!
Fix: Reject audits on EMBEDDED models (SQLMesh#5546)