Skip to content

Bug: create_external_models causes duplicate model ConfigError when using external_models/ directory #5880

Description

@christophmeier90

Steps to reproduce

  1. Create a SQLMesh project with a model referencing an external table:
MODEL (name db.my_model, kind FULL);
SELECT * FROM raw.source_table;
  1. Run sqlmesh create_external_models — the external model is written to external_models.yaml.

  2. Move the entry into the external_models/ directory as recommended in the docs (e.g., external_models/source_table.yaml), then delete external_models.yaml.

  3. Run sqlmesh create_external_models again — the entry is written back into external_models.yaml. The same model now exists in both external_models.yaml and external_models/source_table.yaml.

  4. Run sqlmesh plan or any command that loads models — crashes with:

ConfigError: Failed to load model from file external_models/source_table.yaml:
  Duplicate external model name: memory.raw.source_table.

Why this happens

create_external_models_file writes all fetched external models into external_models.yaml, regardless of whether they already exist in external_models/*.yaml files. The loader then raises a ConfigError when it finds the same model name in two different files.

Workaround

Delete external_models.yaml and re-run create_external_models, or avoid using the external_models/ directory together with create_external_models.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions