Skip to content

Commit 245c76d

Browse files
authored
Fix: Update sys_path before loading models. (#914)
1 parent 9882e69 commit 245c76d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sqlmesh/core/context.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ def refresh(self) -> None:
338338
if self._loader.reload_needed():
339339
self.load()
340340

341-
def load(self) -> Context:
341+
def load(self, update_schemas: bool = True) -> Context:
342342
"""Load all files in the context's path."""
343343
with sys_path(*self.configs):
344-
project = self._loader.load(self)
344+
project = self._loader.load(self, update_schemas)
345345
self._hooks = project.hooks
346346
self._macros = project.macros
347347
self._models = project.models
@@ -844,13 +844,15 @@ def create_external_models(self) -> None:
844844
The schema file contains all columns and types of external models, allowing for more robust
845845
lineage, validation, and optimizations.
846846
"""
847-
models = self._models or self._loader.load(self, update_schemas=False).models
847+
if not self._models:
848+
self.load(update_schemas=False)
849+
848850
for path, config in self.configs.items():
849851
create_schema_file(
850852
path=path / c.SCHEMA_YAML,
851853
models={
852854
name: model
853-
for name, model in models.items()
855+
for name, model in self._models.items()
854856
if self.config_for_model(model) is config
855857
},
856858
adapter=self._engine_adapter,

0 commit comments

Comments
 (0)