@@ -120,22 +120,27 @@ def process_events(
120120 notify = self ._tracker .notify_queue_next ()
121121 while notify is not None :
122122 completed_name , update_status = notify
123+
124+ # If the model is not in the context, we can skip any notification
125+ # This will happen for external models
123126 if not sqlmesh_context .get_model (completed_name ):
124127 notify = self ._tracker .notify_queue_next ()
125128 continue
126- model = self ._models_map [completed_name ]
127- output_key = sqlmesh_model_name_to_key (model .name )
128- asset_key = self ._context .asset_key_for_output (output_key )
129- # asset_key = translator.get_asset_key_from_model(
130- # controller.context, model
131- # )
132- yield MaterializeResult (
133- asset_key = asset_key ,
134- metadata = {
135- "updated" : update_status ,
136- "duration_ms" : 0 ,
137- },
138- )
129+
130+ model = self ._models_map .get (completed_name )
131+
132+ # We allow selecting models. That value is mapped to models_map.
133+ # If the model is not in models_map, we can skip any notification
134+ if model :
135+ output_key = sqlmesh_model_name_to_key (model .name )
136+ asset_key = self ._context .asset_key_for_output (output_key )
137+ yield MaterializeResult (
138+ asset_key = asset_key ,
139+ metadata = {
140+ "updated" : update_status ,
141+ "duration_ms" : 0 ,
142+ },
143+ )
139144 notify = self ._tracker .notify_queue_next ()
140145
141146 def report_event (self , event : console .ConsoleEvent ):
@@ -189,14 +194,14 @@ def report_event(self, event: console.ConsoleEvent):
189194 raise Exception ("sqlmesh failed during run" )
190195 case console .LogError (message ):
191196 log_context .error (
192- message ,
197+ f"sqlmesh reported an error: { message } " ,
193198 )
194199 case console .LogFailedModels (models ):
195- log_context . error (
196- "\n " .join (
200+ if len ( models ) != 0 :
201+ failed_models = "\n " .join (
197202 [f"{ str (model )} \n { str (model .__cause__ )} " for model in models ]
198- ),
199- )
203+ )
204+ log_context . error ( f"sqlmesh failed models: { failed_models } " )
200205 case _:
201206 log_context .debug ("Received event" )
202207
@@ -244,6 +249,8 @@ def run(
244249 dag = mesh .models_dag ()
245250
246251 plan_options ["select_models" ] = []
252+ plan_options ["backfill_models" ] = []
253+ run_options ["select_models" ] = []
247254
248255 models = mesh .models ()
249256 models_map = models .copy ()
@@ -254,7 +261,12 @@ def run(
254261 sqlmesh_model_name_to_key (model .name )
255262 in context .selected_output_names
256263 ):
264+ logger .info (f"selected model: { model .name } " )
265+
257266 models_map [key ] = model
267+ plan_options ["select_models" ].append (model .name )
268+ plan_options ["backfill_models" ].append (model .name )
269+ run_options ["select_models" ].append (model .name )
258270
259271 event_handler = DagsterSQLMeshEventHandler (
260272 context , models_map , dag , "sqlmesh: "
0 commit comments