@@ -28,10 +28,7 @@ def update_model_schemas(
2828 schema = MappingSchema (normalize = False )
2929 optimized_query_cache : OptimizedQueryCache = OptimizedQueryCache (context_path / c .CACHE )
3030
31- if c .MAX_FORK_WORKERS == 1 :
32- _update_model_schemas_sequential (dag , models , schema , optimized_query_cache )
33- else :
34- _update_model_schemas_parallel (dag , models , schema , optimized_query_cache )
31+ _update_model_schemas (dag , models , schema , optimized_query_cache )
3532
3633
3734def _update_schema_with_model (schema : MappingSchema , model : Model ) -> None :
@@ -49,25 +46,7 @@ def _update_schema_with_model(schema: MappingSchema, model: Model) -> None:
4946 raise
5047
5148
52- def _update_model_schemas_sequential (
53- dag : DAG [str ],
54- models : UniqueKeyDict [str , Model ],
55- schema : MappingSchema ,
56- optimized_query_cache : OptimizedQueryCache ,
57- ) -> None :
58- for name in dag .sorted :
59- model = models .get (name )
60-
61- # External models don't exist in the context, so we need to skip them
62- if not model :
63- continue
64-
65- model .update_schema (schema )
66- optimized_query_cache .with_optimized_query (model )
67- _update_schema_with_model (schema , model )
68-
69-
70- def _update_model_schemas_parallel (
49+ def _update_model_schemas (
7150 dag : DAG [str ],
7251 models : UniqueKeyDict [str , Model ],
7352 schema : MappingSchema ,
@@ -102,17 +81,24 @@ def process_models(completed_model: t.Optional[Model] = None) -> None:
10281 )
10382 )
10483
84+ errors : t .List [str ] = []
10585 with optimized_query_cache_pool (optimized_query_cache ) as executor :
10686 process_models ()
10787
108- while futures :
88+ while futures and not errors :
10989 for future in as_completed (futures ):
110- futures .remove (future )
111- fqn , entry_name , data_hash , metadata_hash , mapping_schema = future .result ()
112- model = models [fqn ]
113- model ._data_hash = data_hash
114- model ._metadata_hash = metadata_hash
115- model .set_mapping_schema (mapping_schema )
116- optimized_query_cache .with_optimized_query (model , entry_name )
117- _update_schema_with_model (schema , model )
118- process_models (completed_model = model )
90+ try :
91+ futures .remove (future )
92+ fqn , entry_name , data_hash , metadata_hash , mapping_schema = future .result ()
93+ model = models [fqn ]
94+ model ._data_hash = data_hash
95+ model ._metadata_hash = metadata_hash
96+ model .set_mapping_schema (mapping_schema )
97+ optimized_query_cache .with_optimized_query (model , entry_name )
98+ _update_schema_with_model (schema , model )
99+ process_models (completed_model = model )
100+ except Exception as ex :
101+ errors .append (f"{ ex } " )
102+
103+ if errors :
104+ raise SchemaError (f"Failed to update model schemas\n \n { '\n ' .join (errors )} " )
0 commit comments