Skip to content

Fix: create_external_models misclassifies cross-repo models as external#5745

Merged
StuffbyYuki merged 1 commit into
SQLMesh:mainfrom
gabepesco:fix/multi-repo-create-external-models
May 19, 2026
Merged

Fix: create_external_models misclassifies cross-repo models as external#5745
StuffbyYuki merged 1 commit into
SQLMesh:mainfrom
gabepesco:fix/multi-repo-create-external-models

Conversation

@gabepesco
Copy link
Copy Markdown
Contributor

@gabepesco gabepesco commented Mar 26, 2026

Resolves #5326

Description

In a multi-repo setup, create_external_models partitions models per-config before passing them to create_external_models_file. This caused dependencies that belong to another repo (e.g. bronze.a referenced by silver.c in repo_2) to appear missing from the current config's model set and be incorrectly classified as external.

The fix adds an all_models parameter to create_external_models_file that represents the full set of loaded models across all repos. Dependency resolution uses this complete set, so cross-repo internal models are never mistaken for external ones. The per-config models argument is still used to scope which models' dependencies are written to each repo's external_models.yaml.

Test Plan

Added test_multi_repo_create_external_models in tests/core/integration/test_multi_repo.py using the existing examples/multi fixture. The test verifies that after create_external_models(), no "Unable to get schema" warnings are emitted for cross-repo models, and that plan still resolves all models as internal (no new snapshots treated as external).

Confirmed the test fails without the fix and passes with it. Ran full regression on tests/core/test_schema_loader.py and tests/core/integration/test_multi_repo.py, all passing. I also monkey patched it into my own pipeline, and the warning was gone and no other issues occurred.

Checklist

  • I have run make style and fixed any issues
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test)
  • My commits are signed off (git commit -s) per the DCO

@gabepesco gabepesco changed the title Fix: create_external_models misclassifies cross-repo models as external (#5326) Fix: create_external_models misclassifies cross-repo models as external Mar 26, 2026
@StuffbyYuki
Copy link
Copy Markdown
Collaborator

@gabepesco Hey it looks like a few tests including style ci jobs failed. Could you look into those?

@StuffbyYuki StuffbyYuki force-pushed the fix/multi-repo-create-external-models branch from 31b85eb to e361a4e Compare May 19, 2026 15:10
…al (SQLMesh#5326)

In a multi-repo setup, create_external_models_file partitioned models by
config and processed each repo in isolation. This caused dependencies on
models defined in another repo to be treated as missing, and therefore
classified as external.

Fix: add an optional all_models parameter to create_external_models_file.
When provided (as self._models, which spans all loaded repos), a dependency
is only classified as external if it is absent from the full set. The
per-repo models argument still controls which external_models.yaml gets
written.

Closes SQLMesh#5326

Signed-off-by: Gabe Pesco <PescoG@medinsight.milliman.com>
@gabepesco gabepesco force-pushed the fix/multi-repo-create-external-models branch from 974013a to 6a893df Compare May 19, 2026 17:52
@StuffbyYuki StuffbyYuki merged commit 5e3287e into SQLMesh:main May 19, 2026
31 checks passed
@blecourt-private
Copy link
Copy Markdown
Contributor

Thanks for fixing this @gabepesco!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In a multi repo the create_external_models command has problems with models being defined in one project and selected from in another project

3 participants