Skip to content

Audits on kind EMBEDDED models fail with NotFound error during sqlmesh plan #5546

@mustafaburny

Description

@mustafaburny

Description

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

  1. 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 inlined
    SELECT
      CAST(1 AS INT) AS id,
      'A' AS value
    UNION ALL
    SELECT
      CAST(2 AS INT) AS id,
      'B' AS value;
  2. Run the plan command:

    sqlmesh plan
    

Expected Behavior

  1. Preferred: The CLI should fail project validation immediately upon load with a clear error: "Audits are not permitted on models with kind EMBEDDED."
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ImprovementImproves existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions