@@ -885,6 +885,7 @@ def delete_feature_view(self, name: str, project: str, commit: bool = True):
885885 self ._prepare_registry_for_changes (project )
886886 assert self .cached_registry_proto
887887
888+ found = False
888889 for idx , existing_feature_view_proto in enumerate (
889890 self .cached_registry_proto .feature_views
890891 ):
@@ -893,35 +894,48 @@ def delete_feature_view(self, name: str, project: str, commit: bool = True):
893894 and existing_feature_view_proto .spec .project == project
894895 ):
895896 del self .cached_registry_proto .feature_views [idx ]
896- if commit :
897- self .commit ()
898- return
897+ found = True
898+ break
899899
900- for idx , existing_on_demand_feature_view_proto in enumerate (
901- self .cached_registry_proto .on_demand_feature_views
902- ):
903- if (
904- existing_on_demand_feature_view_proto .spec .name == name
905- and existing_on_demand_feature_view_proto .spec .project == project
900+ if not found :
901+ for idx , existing_on_demand_feature_view_proto in enumerate (
902+ self .cached_registry_proto .on_demand_feature_views
906903 ):
907- del self .cached_registry_proto .on_demand_feature_views [idx ]
908- if commit :
909- self .commit ()
910- return
904+ if (
905+ existing_on_demand_feature_view_proto .spec .name == name
906+ and existing_on_demand_feature_view_proto .spec .project == project
907+ ):
908+ del self .cached_registry_proto .on_demand_feature_views [idx ]
909+ found = True
910+ break
911911
912- for idx , existing_stream_feature_view_proto in enumerate (
913- self .cached_registry_proto .stream_feature_views
914- ):
915- if (
916- existing_stream_feature_view_proto .spec .name == name
917- and existing_stream_feature_view_proto .spec .project == project
912+ if not found :
913+ for idx , existing_stream_feature_view_proto in enumerate (
914+ self .cached_registry_proto .stream_feature_views
918915 ):
919- del self .cached_registry_proto .stream_feature_views [idx ]
920- if commit :
921- self .commit ()
922- return
916+ if (
917+ existing_stream_feature_view_proto .spec .name == name
918+ and existing_stream_feature_view_proto .spec .project == project
919+ ):
920+ del self .cached_registry_proto .stream_feature_views [idx ]
921+ found = True
922+ break
923923
924- raise FeatureViewNotFoundException (name , project )
924+ if not found :
925+ raise FeatureViewNotFoundException (name , project )
926+
927+ # Clean up version history for the deleted feature view
928+ history = self .cached_registry_proto .feature_view_version_history
929+ indices_to_remove = [
930+ i
931+ for i , record in enumerate (history .records )
932+ if record .feature_view_name == name and record .project_id == project
933+ ]
934+ for i in reversed (indices_to_remove ):
935+ del history .records [i ]
936+
937+ if commit :
938+ self .commit ()
925939
926940 def delete_entity (self , name : str , project : str , commit : bool = True ):
927941 self ._prepare_registry_for_changes (project )
0 commit comments