1
1
from 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
3
3
4
4
from feast .base_feature_view import BaseFeatureView
5
5
from feast .diff .property_diff import PropertyDiff , TransitionType
6
6
from feast .entity import Entity
7
+ from feast .feast_object import FeastObject
7
8
from feast .feature_service import FeatureService
8
9
from feast .feature_view import DUMMY_ENTITY_NAME
9
10
from feast .protos .feast .core .Entity_pb2 import Entity as EntityProto
20
21
from feast .registry import FEAST_OBJECT_TYPES , FeastObjectType , Registry
21
22
from feast .repo_contents import RepoContents
22
23
23
- FeastObject = TypeVar ("FeastObject" , Entity , BaseFeatureView , FeatureService )
24
-
25
24
26
25
@dataclass
27
- class FeastObjectDiff ( Generic [ FeastObject ]) :
26
+ class FeastObjectDiff :
28
27
name : str
29
28
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 ]
32
31
feast_object_property_diffs : List [PropertyDiff ]
33
32
transition_type : TransitionType
34
33
@@ -257,20 +256,25 @@ def apply_diff_to_registry(
257
256
# will automatically delete the existing object.
258
257
if feast_object_diff .transition_type == TransitionType .DELETE :
259
258
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 )
263
261
elif feast_object_diff .feast_object_type == FeastObjectType .FEATURE_SERVICE :
262
+ feature_service_obj = cast (
263
+ FeatureService , feast_object_diff .current_feast_object
264
+ )
264
265
registry .delete_feature_service (
265
- feast_object_diff . current_feast_object .name , project , commit = False
266
+ feature_service_obj .name , project , commit = False
266
267
)
267
268
elif feast_object_diff .feast_object_type in [
268
269
FeastObjectType .FEATURE_VIEW ,
269
270
FeastObjectType .ON_DEMAND_FEATURE_VIEW ,
270
271
FeastObjectType .REQUEST_FEATURE_VIEW ,
271
272
]:
273
+ feature_view_obj = cast (
274
+ BaseFeatureView , feast_object_diff .current_feast_object
275
+ )
272
276
registry .delete_feature_view (
273
- feast_object_diff . current_feast_object .name , project , commit = False ,
277
+ feature_view_obj .name , project , commit = False ,
274
278
)
275
279
276
280
if feast_object_diff .transition_type in [
@@ -279,19 +283,25 @@ def apply_diff_to_registry(
279
283
]:
280
284
if feast_object_diff .feast_object_type == FeastObjectType .ENTITY :
281
285
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 ,
283
289
)
284
290
elif feast_object_diff .feast_object_type == FeastObjectType .FEATURE_SERVICE :
285
291
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 ,
287
295
)
288
296
elif feast_object_diff .feast_object_type in [
289
297
FeastObjectType .FEATURE_VIEW ,
290
298
FeastObjectType .ON_DEMAND_FEATURE_VIEW ,
291
299
FeastObjectType .REQUEST_FEATURE_VIEW ,
292
300
]:
293
301
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 ,
295
305
)
296
306
297
307
if commit :
0 commit comments