Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions sqlmesh/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2649,13 +2649,16 @@ def cache_dir(self) -> Path:

@cached_property
def engine_adapters(self) -> t.Dict[str, EngineAdapter]:
"""Returns all the engine adapters for the gateways defined in the configuration."""
"""Returns all the engine adapters for the gateways defined in the configurations."""
adapters: t.Dict[str, EngineAdapter] = {self.selected_gateway: self.engine_adapter}
for gateway_name in self.config.gateways:
if gateway_name != self.selected_gateway:
connection = self.config.get_connection(gateway_name)
adapter = connection.create_engine_adapter(concurrent_tasks=self.concurrent_tasks)
adapters[gateway_name] = adapter
for config in self.configs.values():
for gateway_name in config.gateways:
if gateway_name not in adapters:
connection = config.get_connection(gateway_name)
adapter = connection.create_engine_adapter(
concurrent_tasks=self.concurrent_tasks,
)
adapters[gateway_name] = adapter
return adapters

@cached_property
Expand Down
36 changes: 36 additions & 0 deletions tests/core/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from unittest import mock
from unittest.mock import patch
import logging
from textwrap import dedent
import os
import numpy as np # noqa: TID253
import pandas as pd # noqa: TID253
Expand Down Expand Up @@ -7079,3 +7080,38 @@ def test_scd_type_2_regular_run_with_offset(init_and_plan_context: t.Callable):
assert restated_data.iloc[1]["region"] == "ANZ"
assert str(restated_data.iloc[1]["valid_from"]) == "2023-01-09 07:26:00"
assert pd.isna(restated_data.iloc[1]["valid_to"])


def test_engine_adapters_multi_repo_all_gateways_gathered(copy_to_temp_path):
paths = copy_to_temp_path("examples/multi")
repo_1_path = paths[0] / "repo_1"
repo_2_path = paths[0] / "repo_2"

# Add an extra gateway to repo_2's config
repo_2_config_path = repo_2_path / "config.yaml"
config_content = repo_2_config_path.read_text()

modified_config = config_content.replace(
"default_gateway: local",
dedent("""
extra:
connection:
type: duckdb
database: extra.duckdb

default_gateway: local
"""),
)

repo_2_config_path.write_text(modified_config)

# Create context with both repos but using the repo_1 path first
context = Context(
paths=(repo_1_path, repo_2_path),
gateway="memory",
)

# Verify all gateways from both repos are present
gathered_gateways = context.engine_adapters.keys()
expected_gateways = {"local", "memory", "extra"}
assert gathered_gateways == expected_gateways