Skip to content

Commit a464f8e

Browse files
committed
fix: address more issues with moving config around
1 parent 2181faa commit a464f8e

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

dagster_sqlmesh/config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from sqlmesh.core.config import Config as MeshConfig
88
from sqlmesh.core.config.loader import load_configs
99

10-
if t.TYPE_CHECKING:
11-
from dagster_sqlmesh.translator import SQLMeshDagsterTranslator
10+
from dagster_sqlmesh.translator import SQLMeshDagsterTranslator
1211

1312

1413
@dataclass
@@ -73,7 +72,7 @@ class and return a different translator. However, due to the way that
7372
gateway: str
7473
config_override: dict[str, t.Any] | None = Field(default_factory=lambda: None)
7574

76-
def get_translator(self) -> "SQLMeshDagsterTranslator":
75+
def get_translator(self) -> SQLMeshDagsterTranslator:
7776
"""Get a translator instance. Override this method to provide a custom translator.
7877
7978
Returns:

dagster_sqlmesh/resource.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ def run(
606606
logger = context.log
607607

608608
controller = self.get_controller(
609-
context_factory=context_factory, log_override=logger
609+
config=config,
610+
context_factory=context_factory,
611+
log_override=logger
610612
)
611613

612614
with controller.instance(environment) as mesh:
@@ -738,11 +740,12 @@ def _get_selected_models_from_context(
738740

739741
def get_controller(
740742
self,
743+
config: SQLMeshContextConfig,
741744
context_factory: ContextFactory[ContextCls],
742745
log_override: logging.Logger | None = None,
743746
) -> DagsterSQLMeshController[ContextCls]:
744747
return DagsterSQLMeshController.setup_with_config(
745-
config=self.config,
748+
config=config,
746749
context_factory=context_factory,
747750
log_override=log_override,
748751
)

dagster_sqlmesh/test_resource.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ def test_sqlmesh_resource_should_report_no_errors(
5959
):
6060
resource = sample_sqlmesh_resource_initialization.resource
6161
dg_context = sample_sqlmesh_resource_initialization.dagster_context
62+
context_config = sample_sqlmesh_resource_initialization.test_context.context_config
6263

6364
success = True
6465
try:
65-
for result in resource.run(dg_context):
66+
for result in resource.run(context=dg_context, config=context_config):
6667
pass
6768
except PlanOrRunFailedError as e:
6869
success = False
@@ -83,10 +84,11 @@ def test_sqlmesh_resource_properly_reports_errors(
8384
)
8485
resource = sqlmesh_resource_initialization.resource
8586
dg_context = sqlmesh_resource_initialization.dagster_context
87+
context_config = sqlmesh_resource_initialization.test_context.context_config
8688

8789
caught_failure = False
8890
try:
89-
for result in resource.run(dg_context):
91+
for result in resource.run(context=dg_context, config=context_config):
9092
pass
9193
except PlanOrRunFailedError as e:
9294
caught_failure = True
@@ -106,6 +108,7 @@ def test_sqlmesh_resource_properly_reports_errors_not_thrown(
106108
):
107109
dg_context = sample_sqlmesh_resource_initialization.dagster_context
108110
resource = sample_sqlmesh_resource_initialization.resource
111+
context_config = sample_sqlmesh_resource_initialization.test_context.context_config
109112

110113
def event_handler_factory(
111114
*args: t.Any, **kwargs: t.Any
@@ -120,7 +123,7 @@ def event_handler_factory(
120123

121124
caught_failure = False
122125
try:
123-
for result in resource.run(dg_context):
126+
for result in resource.run(context=dg_context, config=context_config):
124127
pass
125128
except PlanOrRunFailedError as e:
126129
caught_failure = True
@@ -151,17 +154,19 @@ def test_sqlmesh_resource_should_properly_materialize_results_when_no_plan_is_ru
151154
resource = sample_sqlmesh_resource_initialization.resource
152155
dg_context = sample_sqlmesh_resource_initialization.dagster_context
153156
dg_instance = sample_sqlmesh_resource_initialization.dagster_instance
157+
context_config = sample_sqlmesh_resource_initialization.test_context.context_config
154158

155159
# First run should materialize all models
156160
initial_results: list[dg.MaterializeResult] = []
157-
for result in resource.run(dg_context):
161+
for result in resource.run(context=dg_context, config=context_config):
158162
initial_results.append(result)
159163
assert result.asset_key is not None, "Expected asset key to be present."
160-
dg_instance.report_runless_asset_event(dg.AssetMaterialization(
161-
asset_key=result.asset_key,
162-
metadata=result.metadata,
163-
))
164-
164+
dg_instance.report_runless_asset_event(
165+
dg.AssetMaterialization(
166+
asset_key=result.asset_key,
167+
metadata=result.metadata,
168+
)
169+
)
165170

166171
# All metadata times should be set to the same time
167172
initial_times: set[float] = set()
@@ -180,7 +185,7 @@ def test_sqlmesh_resource_should_properly_materialize_results_when_no_plan_is_ru
180185

181186
# Second run should also materialize all models
182187
second_results: list[dg.MaterializeResult] = []
183-
for result in resource.run(dg_context):
188+
for result in resource.run(context=dg_context, config=context_config):
184189
second_results.append(result)
185190

186191
assert len(second_results) > 0, "Expected second results to be non-empty."
@@ -204,7 +209,9 @@ def test_sqlmesh_resource_should_properly_materialize_results_when_no_plan_is_ru
204209
# Third run will restate the full model
205210
third_results: list[dg.MaterializeResult] = []
206211
for result in resource.run(
207-
dg_context, restate_models=["sqlmesh_example.full_model"]
212+
context=dg_context,
213+
config=context_config,
214+
restate_models=["sqlmesh_example.full_model"],
208215
):
209216
third_results.append(result)
210217

dagster_sqlmesh/testing/context.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class TestSQLMeshResource(SQLMeshResource):
5656
It allows for easy setup and teardown of the SQLMesh context.
5757
"""
5858

59-
def __init__(self, config: SQLMeshContextConfig, is_testing: bool = False):
60-
super().__init__(config=config, is_testing=is_testing)
59+
def __init__(self, is_testing: bool = False):
60+
super().__init__(is_testing=is_testing)
6161
def default_event_handler_factory(*args: t.Any, **kwargs: t.Any) -> DagsterSQLMeshEventHandler:
6262
"""Default event handler factory for the SQLMesh resource."""
6363
return DagsterSQLMeshEventHandler(*args, **kwargs)
@@ -82,7 +82,9 @@ def create_event_handler(self, *args: t.Any, **kwargs: t.Any) -> DagsterSQLMeshE
8282
DagsterSQLMeshEventHandler: The created event handler.
8383
"""
8484
# Ensure translator is passed to the event handler factory
85-
kwargs['translator'] = self.config.get_translator()
85+
# FIXME: this is a hack to deal with an older signature that didn't expected the config
86+
config = t.cast(SQLMeshContextConfig, kwargs.pop("config"))
87+
kwargs["translator"] = config.get_translator()
8688
return self._event_handler_factory(*args, **kwargs)
8789

8890

@@ -99,9 +101,7 @@ def create_controller(self) -> DagsterSQLMeshController[Context]:
99101
)
100102

101103
def create_resource(self) -> TestSQLMeshResource:
102-
return TestSQLMeshResource(
103-
config=self.context_config, is_testing=True,
104-
)
104+
return TestSQLMeshResource(is_testing=True)
105105

106106
def query(self, *args: t.Any, **kwargs: t.Any) -> list[t.Any]:
107107
conn = duckdb.connect(self.db_path)

0 commit comments

Comments
 (0)