sqlmesh icon indicating copy to clipboard operation
sqlmesh copied to clipboard

Detect and warn when regular model name also in external models

Open treysp opened this issue 1 year ago • 5 comments

A project has a model named example.model. Someone accidentally adds example.model to the external models config file.

Currently, this generates unclear output - sqlmesh should detect and warn so users can resolve.

treysp avatar Jan 22 '25 18:01 treysp

@treysp what output is generated today?

izeigerman avatar Jan 23 '25 16:01 izeigerman

So given this entry in external_models.yaml of the example project:

- name: sqlmesh_example.full_model
  start: 1 week ago
  columns:
    customer_id: int
    zip: text

The resulting error is:

sqlmesh.utils.errors.TestError: Model '"db"."sqlmesh_example"."full_model"' is an unsupported model type for testing at /<path>/playground/tests/test_full_model.yaml

I believe this happens because we're using update in this section: https://github.com/TobikoData/sqlmesh/blob/cc0653c351232d917c103212aa497d094b9a0001/sqlmesh/core/loader.py#L387-L389

So the SQL kind is overwritten by the external kind, which can't be unit-tested, hence that cryptic error message. Is the usage of update in the linked section intentional? I'd assume that we want to enforce the unique name constraint for models across all kinds.

georgesittas avatar Jan 28 '25 00:01 georgesittas

Recently, I encountered an issue similar to this, so I created a PR for that https://github.com/TobikoData/sqlmesh/pull/3945 to handle. appreciate your feedback.

lafirm avatar Mar 05 '25 11:03 lafirm

@tobymao - PR is merged, think it can be closed now :)

lafirm avatar Mar 13 '25 00:03 lafirm

Appreciate your working on this @lafirm!

georgesittas avatar Mar 13 '25 00:03 georgesittas