@@ -116,18 +116,24 @@ def parse_repo(repo_root: Path) -> ParsedRepo:
116116 return res
117117
118118
119- def apply_feature_services (registry : Registry , project : str , repo : ParsedRepo ):
119+ def apply_feature_services (
120+ registry : Registry ,
121+ project : str ,
122+ repo : ParsedRepo ,
123+ existing_feature_services : List [FeatureService ],
124+ ):
120125 from colorama import Fore , Style
121126
122127 # Determine which feature services should be deleted.
123- existing_feature_services = registry .list_feature_services (project )
124128 for feature_service in repo .feature_services :
125129 if feature_service in existing_feature_services :
126130 existing_feature_services .remove (feature_service )
127131
128132 # The remaining features services in the list should be deleted.
129133 for feature_service_to_delete in existing_feature_services :
130- registry .delete_feature_service (feature_service_to_delete .name , project )
134+ registry .delete_feature_service (
135+ feature_service_to_delete .name , project , commit = False
136+ )
131137 click .echo (
132138 f"Deleted feature service { Style .BRIGHT + Fore .GREEN } { feature_service_to_delete .name } { Style .RESET_ALL } "
133139 f"from registry"
@@ -192,6 +198,16 @@ def apply_total(repo_config: RepoConfig, repo_path: Path, skip_source_validation
192198 if registry_view .name not in repo_table_names :
193199 views_to_delete .append (registry_view )
194200
201+ entities_to_delete : List [Entity ] = []
202+ repo_entities_names = set ([e .name for e in repo .entities ])
203+ for registry_entity in registry .list_entities (project = project ):
204+ if registry_entity .name not in repo_entities_names :
205+ entities_to_delete .append (registry_entity )
206+
207+ entities_to_keep : List [Entity ] = repo .entities
208+
209+ existing_feature_services = registry .list_feature_services (project )
210+
195211 sys .dont_write_bytecode = False
196212 for entity in repo .entities :
197213 registry .apply_entity (entity , project = project , commit = False )
@@ -228,9 +244,8 @@ def apply_total(repo_config: RepoConfig, repo_path: Path, skip_source_validation
228244 click .echo (
229245 f"Registered feature view { Style .BRIGHT + Fore .GREEN } { view .name } { Style .RESET_ALL } "
230246 )
231- registry .commit ()
232247
233- apply_feature_services (registry , project , repo )
248+ apply_feature_services (registry , project , repo , existing_feature_services )
234249
235250 infra_provider = get_provider (repo_config , repo_path )
236251
@@ -242,14 +257,6 @@ def apply_total(repo_config: RepoConfig, repo_path: Path, skip_source_validation
242257 all_to_keep .extend (repo .feature_tables )
243258 all_to_keep .extend (repo .feature_views )
244259
245- entities_to_delete : List [Entity ] = []
246- repo_entities_names = set ([e .name for e in repo .entities ])
247- for registry_entity in registry .list_entities (project = project ):
248- if registry_entity .name not in repo_entities_names :
249- entities_to_delete .append (registry_entity )
250-
251- entities_to_keep : List [Entity ] = repo .entities
252-
253260 for name in [view .name for view in repo .feature_tables ] + [
254261 table .name for table in repo .feature_views
255262 ]:
@@ -272,6 +279,9 @@ def apply_total(repo_config: RepoConfig, repo_path: Path, skip_source_validation
272279 partial = False ,
273280 )
274281
282+ # Commit the update to the registry only after successful infra update
283+ registry .commit ()
284+
275285
276286@log_exceptions_and_usage
277287def teardown (repo_config : RepoConfig , repo_path : Path ):
0 commit comments