Skip to content

Commit b72c2da

Browse files
authored
fix: Incorrect type passed to assert_permissions in materialize endpoints (feast-dev#4727)
1 parent e9cd373 commit b72c2da

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

sdk/python/feast/feature_server.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
FeastError,
2525
FeatureViewNotFoundException,
2626
)
27+
from feast.feast_object import FeastObject
2728
from feast.permissions.action import WRITE, AuthzedAction
2829
from feast.permissions.security_manager import assert_permissions
2930
from feast.permissions.server.rest import inject_user_details
@@ -218,21 +219,25 @@ async def push(request: PushFeaturesRequest) -> None:
218219
else:
219220
store.push(**push_params)
220221

221-
@app.post("/write-to-online-store", dependencies=[Depends(inject_user_details)])
222-
def write_to_online_store(request: WriteToFeatureStoreRequest) -> None:
223-
df = pd.DataFrame(request.df)
224-
feature_view_name = request.feature_view_name
225-
allow_registry_cache = request.allow_registry_cache
222+
def _get_feast_object(
223+
feature_view_name: str, allow_registry_cache: bool
224+
) -> FeastObject:
226225
try:
227-
feature_view = store.get_stream_feature_view( # type: ignore
226+
return store.get_stream_feature_view( # type: ignore
228227
feature_view_name, allow_registry_cache=allow_registry_cache
229228
)
230229
except FeatureViewNotFoundException:
231-
feature_view = store.get_feature_view( # type: ignore
230+
return store.get_feature_view( # type: ignore
232231
feature_view_name, allow_registry_cache=allow_registry_cache
233232
)
234233

235-
assert_permissions(resource=feature_view, actions=[AuthzedAction.WRITE_ONLINE])
234+
@app.post("/write-to-online-store", dependencies=[Depends(inject_user_details)])
235+
def write_to_online_store(request: WriteToFeatureStoreRequest) -> None:
236+
df = pd.DataFrame(request.df)
237+
feature_view_name = request.feature_view_name
238+
allow_registry_cache = request.allow_registry_cache
239+
resource = _get_feast_object(feature_view_name, allow_registry_cache)
240+
assert_permissions(resource=resource, actions=[AuthzedAction.WRITE_ONLINE])
236241
store.write_to_online_store(
237242
feature_view_name=feature_view_name,
238243
df=df,
@@ -250,9 +255,8 @@ async def health():
250255
@app.post("/materialize", dependencies=[Depends(inject_user_details)])
251256
def materialize(request: MaterializeRequest) -> None:
252257
for feature_view in request.feature_views or []:
253-
# TODO: receives a str for resource but isn't in the Union. is str actually allowed?
254258
assert_permissions(
255-
resource=feature_view, # type: ignore
259+
resource=_get_feast_object(feature_view, True),
256260
actions=[AuthzedAction.WRITE_ONLINE],
257261
)
258262
store.materialize(
@@ -264,9 +268,8 @@ def materialize(request: MaterializeRequest) -> None:
264268
@app.post("/materialize-incremental", dependencies=[Depends(inject_user_details)])
265269
def materialize_incremental(request: MaterializeIncrementalRequest) -> None:
266270
for feature_view in request.feature_views or []:
267-
# TODO: receives a str for resource but isn't in the Union. is str actually allowed?
268271
assert_permissions(
269-
resource=feature_view, # type: ignore
272+
resource=_get_feast_object(feature_view, True),
270273
actions=[AuthzedAction.WRITE_ONLINE],
271274
)
272275
store.materialize_incremental(

0 commit comments

Comments
 (0)