Skip to content

Commit 9a954d7

Browse files
authored
Fix: Create engine_adapters from all projects (#4977)
1 parent 2b702ba commit 9a954d7

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

sqlmesh/core/context.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,13 +2649,16 @@ def cache_dir(self) -> Path:
26492649

26502650
@cached_property
26512651
def engine_adapters(self) -> t.Dict[str, EngineAdapter]:
2652-
"""Returns all the engine adapters for the gateways defined in the configuration."""
2652+
"""Returns all the engine adapters for the gateways defined in the configurations."""
26532653
adapters: t.Dict[str, EngineAdapter] = {self.selected_gateway: self.engine_adapter}
2654-
for gateway_name in self.config.gateways:
2655-
if gateway_name != self.selected_gateway:
2656-
connection = self.config.get_connection(gateway_name)
2657-
adapter = connection.create_engine_adapter(concurrent_tasks=self.concurrent_tasks)
2658-
adapters[gateway_name] = adapter
2654+
for config in self.configs.values():
2655+
for gateway_name in config.gateways:
2656+
if gateway_name not in adapters:
2657+
connection = config.get_connection(gateway_name)
2658+
adapter = connection.create_engine_adapter(
2659+
concurrent_tasks=self.concurrent_tasks,
2660+
)
2661+
adapters[gateway_name] = adapter
26592662
return adapters
26602663

26612664
@cached_property

tests/core/test_integration.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from unittest import mock
88
from unittest.mock import patch
99
import logging
10+
from textwrap import dedent
1011
import os
1112
import numpy as np # noqa: TID253
1213
import pandas as pd # noqa: TID253
@@ -7079,3 +7080,38 @@ def test_scd_type_2_regular_run_with_offset(init_and_plan_context: t.Callable):
70797080
assert restated_data.iloc[1]["region"] == "ANZ"
70807081
assert str(restated_data.iloc[1]["valid_from"]) == "2023-01-09 07:26:00"
70817082
assert pd.isna(restated_data.iloc[1]["valid_to"])
7083+
7084+
7085+
def test_engine_adapters_multi_repo_all_gateways_gathered(copy_to_temp_path):
7086+
paths = copy_to_temp_path("examples/multi")
7087+
repo_1_path = paths[0] / "repo_1"
7088+
repo_2_path = paths[0] / "repo_2"
7089+
7090+
# Add an extra gateway to repo_2's config
7091+
repo_2_config_path = repo_2_path / "config.yaml"
7092+
config_content = repo_2_config_path.read_text()
7093+
7094+
modified_config = config_content.replace(
7095+
"default_gateway: local",
7096+
dedent("""
7097+
extra:
7098+
connection:
7099+
type: duckdb
7100+
database: extra.duckdb
7101+
7102+
default_gateway: local
7103+
"""),
7104+
)
7105+
7106+
repo_2_config_path.write_text(modified_config)
7107+
7108+
# Create context with both repos but using the repo_1 path first
7109+
context = Context(
7110+
paths=(repo_1_path, repo_2_path),
7111+
gateway="memory",
7112+
)
7113+
7114+
# Verify all gateways from both repos are present
7115+
gathered_gateways = context.engine_adapters.keys()
7116+
expected_gateways = {"local", "memory", "extra"}
7117+
assert gathered_gateways == expected_gateways

0 commit comments

Comments
 (0)