11from dataclasses import dataclass
2- from typing import Any , Dict , Generic , Iterable , List , Set , Tuple , TypeVar
2+ from typing import Any , Dict , Iterable , List , Optional , Set , Tuple , TypeVar , cast
33
44from feast .base_feature_view import BaseFeatureView
55from feast .diff .property_diff import PropertyDiff , TransitionType
66from feast .entity import Entity
7+ from feast .feast_object import FeastObject
78from feast .feature_service import FeatureService
89from feast .feature_view import DUMMY_ENTITY_NAME
910from feast .protos .feast .core .Entity_pb2 import Entity as EntityProto
2021from feast .registry import FEAST_OBJECT_TYPES , FeastObjectType , Registry
2122from feast .repo_contents import RepoContents
2223
23- FeastObject = TypeVar ("FeastObject" , Entity , BaseFeatureView , FeatureService )
24-
2524
2625@dataclass
27- class FeastObjectDiff ( Generic [ FeastObject ]) :
26+ class FeastObjectDiff :
2827 name : str
2928 feast_object_type : FeastObjectType
30- current_feast_object : FeastObject
31- new_feast_object : FeastObject
29+ current_feast_object : Optional [ FeastObject ]
30+ new_feast_object : Optional [ FeastObject ]
3231 feast_object_property_diffs : List [PropertyDiff ]
3332 transition_type : TransitionType
3433
@@ -257,20 +256,25 @@ def apply_diff_to_registry(
257256 # will automatically delete the existing object.
258257 if feast_object_diff .transition_type == TransitionType .DELETE :
259258 if feast_object_diff .feast_object_type == FeastObjectType .ENTITY :
260- registry .delete_entity (
261- feast_object_diff .current_feast_object .name , project , commit = False
262- )
259+ entity_obj = cast (Entity , feast_object_diff .current_feast_object )
260+ registry .delete_entity (entity_obj .name , project , commit = False )
263261 elif feast_object_diff .feast_object_type == FeastObjectType .FEATURE_SERVICE :
262+ feature_service_obj = cast (
263+ FeatureService , feast_object_diff .current_feast_object
264+ )
264265 registry .delete_feature_service (
265- feast_object_diff . current_feast_object .name , project , commit = False
266+ feature_service_obj .name , project , commit = False
266267 )
267268 elif feast_object_diff .feast_object_type in [
268269 FeastObjectType .FEATURE_VIEW ,
269270 FeastObjectType .ON_DEMAND_FEATURE_VIEW ,
270271 FeastObjectType .REQUEST_FEATURE_VIEW ,
271272 ]:
273+ feature_view_obj = cast (
274+ BaseFeatureView , feast_object_diff .current_feast_object
275+ )
272276 registry .delete_feature_view (
273- feast_object_diff . current_feast_object .name , project , commit = False ,
277+ feature_view_obj .name , project , commit = False ,
274278 )
275279
276280 if feast_object_diff .transition_type in [
@@ -279,19 +283,25 @@ def apply_diff_to_registry(
279283 ]:
280284 if feast_object_diff .feast_object_type == FeastObjectType .ENTITY :
281285 registry .apply_entity (
282- feast_object_diff .new_feast_object , project , commit = False
286+ cast (Entity , feast_object_diff .new_feast_object ),
287+ project ,
288+ commit = False ,
283289 )
284290 elif feast_object_diff .feast_object_type == FeastObjectType .FEATURE_SERVICE :
285291 registry .apply_feature_service (
286- feast_object_diff .new_feast_object , project , commit = False
292+ cast (FeatureService , feast_object_diff .new_feast_object ),
293+ project ,
294+ commit = False ,
287295 )
288296 elif feast_object_diff .feast_object_type in [
289297 FeastObjectType .FEATURE_VIEW ,
290298 FeastObjectType .ON_DEMAND_FEATURE_VIEW ,
291299 FeastObjectType .REQUEST_FEATURE_VIEW ,
292300 ]:
293301 registry .apply_feature_view (
294- feast_object_diff .new_feast_object , project , commit = False
302+ cast (BaseFeatureView , feast_object_diff .new_feast_object ),
303+ project ,
304+ commit = False ,
295305 )
296306
297307 if commit :
0 commit comments