Skip to content

Commit f7c7d0a

Browse files
Fix: Variadic argument issue in loaders (#3147)
1 parent 744b9d2 commit f7c7d0a

5 files changed

Lines changed: 23 additions & 24 deletions

File tree

sqlmesh/core/context.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from io import StringIO
4646
from pathlib import Path
4747
from shutil import rmtree
48-
from types import MappingProxyType
48+
from types import MappingProxyType, SimpleNamespace
4949

5050
import pandas as pd
5151
from sqlglot import Dialect, exp
@@ -318,9 +318,7 @@ def __init__(
318318
self.configs = (
319319
config if isinstance(config, dict) else load_configs(config, self.CONFIG_TYPE, paths)
320320
)
321-
self._loaders: UniqueKeyDict[str, t.Dict[str, Loader | t.Dict[Path, C]]] = UniqueKeyDict(
322-
"loaders"
323-
)
321+
self._loaders: UniqueKeyDict[str, SimpleNamespace] = UniqueKeyDict("loaders")
324322
self.dag: DAG[str] = DAG()
325323
self._models: UniqueKeyDict[str, Model] = UniqueKeyDict("models")
326324
self._audits: UniqueKeyDict[str, ModelAudit] = UniqueKeyDict("audits")
@@ -337,11 +335,10 @@ def __init__(
337335
for path, config in self.configs.items():
338336
project_type = c.DBT if issubclass(config.loader, DbtLoader) else c.NATIVE
339337
if project_type not in self._loaders:
340-
self._loaders[project_type] = {
341-
"loader": (loader or config.loader)(**config.loader_kwargs),
342-
"configs": {},
343-
}
344-
self._loaders[project_type]["configs"][path] = config
338+
self._loaders[project_type] = SimpleNamespace(
339+
loader=(loader or config.loader)(**config.loader_kwargs), configs={}
340+
)
341+
self._loaders[project_type].configs[path] = config
345342

346343
self.project_type = c.HYBRID if len(self._loaders) > 1 else project_type
347344
self._all_dialects: t.Set[str] = {self.config.dialect or ""}
@@ -528,17 +525,17 @@ def state_reader(self) -> StateReader:
528525

529526
def refresh(self) -> None:
530527
"""Refresh all models that have been updated."""
531-
if any(loader_dict["loader"].reload_needed() for loader_dict in self._loaders.values()):
528+
if any(context_loader.loader.reload_needed() for context_loader in self._loaders.values()):
532529
self.load()
533530

534531
def load(self, update_schemas: bool = True) -> GenericContext[C]:
535532
"""Load all files in the context's path."""
536533
load_start_ts = time.perf_counter()
537534

538535
projects = []
539-
for loader_dict in self._loaders.values():
540-
with sys_path(*loader_dict["configs"]):
541-
projects.append(loader_dict["loader"].load(self, update_schemas))
536+
for context_loader in self._loaders.values():
537+
with sys_path(*context_loader.configs):
538+
projects.append(context_loader.loader.load(self, update_schemas))
542539

543540
self._standalone_audits.clear()
544541
self._audits.clear()
@@ -620,9 +617,9 @@ def run(
620617

621618
if not self._loaded:
622619
# Signals should be loaded to run correctly.
623-
for loader_dict in self._loaders.values():
624-
with sys_path(*loader_dict["configs"]):
625-
loader_dict["loader"].load_signals(self)
620+
for context_loader in self._loaders.values():
621+
with sys_path(*context_loader.configs):
622+
context_loader.loader.load_signals(self)
626623

627624
success = False
628625
try:

sqlmesh/core/loader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,14 @@ def _load_sql_models(
321321
) -> UniqueKeyDict[str, Model]:
322322
"""Loads the sql models into a Dict"""
323323
models: UniqueKeyDict[str, Model] = UniqueKeyDict("models")
324-
for context_path, config in self._context._loaders[c.NATIVE]["configs"].items():
324+
for context_path, config in self._context._loaders[c.NATIVE].configs.items():
325325
cache = SqlMeshLoader._Cache(self, context_path)
326326
variables = self._variables(config)
327327

328328
for path in self._glob_paths(
329-
context_path / c.MODELS, ignore_patterns=config.ignore_patterns, extension=".sql"
329+
context_path / c.MODELS,
330+
ignore_patterns=config.ignore_patterns,
331+
extension=".sql",
330332
):
331333
if not os.path.getsize(path):
332334
continue

sqlmesh/dbt/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def _load_projects(self) -> t.List[Project]:
155155

156156
self._projects = []
157157

158-
for path, config in self._context._loaders[c.DBT]["configs"].items():
158+
for path, config in self._context._loaders[c.DBT].configs.items():
159159
project = Project.load(
160160
DbtContext(
161161
project_root=path,

tests/dbt/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@pytest.fixture()
1414
def sushi_test_project(sushi_test_dbt_context: Context) -> Project:
15-
return sushi_test_dbt_context._loaders[c.DBT]["loader"]._load_projects()[0] # type: ignore
15+
return sushi_test_dbt_context._loaders[c.DBT].loader._load_projects()[0] # type: ignore
1616

1717

1818
@pytest.fixture()

web/server/watcher.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ async def watch_project() -> None:
7676
if context:
7777
in_paths = any(is_relative_to(path, p) for p in paths)
7878
is_modified_new_file = change == Change.modified and any(
79-
path not in loader_dict["loader"]._path_mtimes
80-
for loader_dict in context._loaders.values()
79+
path not in context_loader.loader._path_mtimes
80+
for context_loader in context._loaders.values()
8181
)
8282
should_track_file = path.is_file() and in_paths
8383
should_reset_mtime = Change.added or is_modified_new_file
8484
if should_track_file and should_reset_mtime:
85-
for loader_dict in context._loaders:
86-
loader_dict["loader"]._path_mtimes[path] = 0
85+
for context_loader in context._loaders.values():
86+
context_loader.loader._path_mtimes[path] = 0
8787

8888
except Exception:
8989
error = ApiException(

0 commit comments

Comments
 (0)