Skip to content

Nesting errors due to external_models.yaml: Difficult to debug #4906

Open
@MarcusRisanger

Description

@MarcusRisanger

See conversation here: https://tobiko-data.slack.com/archives/C044BRE5W4S/p1751631197964989

Long story short: I was a bad boy when creating a new model, where I omitted the schema from a table reference. This caused the "same level of nesting" error to come out and play, but the error text wasn't very helpful in understanding the source of the problem.

Steps (using MSSQL):

  1. Create a model where a "legit" table reference is used: SELECT * FROM dbo.some_table
  2. Run sqlmesh create_external_models to populate the yaml file
  3. Create another model where schema is omitted: SELECT a,b,c from some_table
  4. Again run sqlmesh create_external_models , this adds another entry for some_table in the yaml file (without db/schema).
  5. Now when trying to do sqlmesh plan, the error shows up
  6. I fix the table reference in the second model, adding schema
  7. The error persists, even though the only place some_table is referenced sans schema is in the external_models.yaml file

In my project with many table references, it seemed to pick a table reference "at random" to throw the error, which made the debugging feel quite hopeless, especially after there was no longer any sql files in the project that had table references without a schema attached!

The error persisted until I deleted and remade the yaml file after fixing all the table references.

Perhaps the create_external_models should automatically fail if it notices different nesting of model references - this would prevent this issue from happening in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions