FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Refresh the SQL registry cache after deleting a permission by LuisFigueroaG · Pull Request #6953 · feast-dev/feast · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
19 changes: 8 additions & 11 deletions sdk/python/feast/infra/registry/sql.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1751,9 +1751,11 @@ def _delete_object(
if not self.purge_feast_metadata:
self._set_last_updated_metadata(_utc_now(), project, conn)

if self.cache_mode == "sync":
self.refresh()
return rows.rowcount
# Refresh only after the transaction commits, otherwise the cache is
# rebuilt from a snapshot that still contains the deleted object.
if self.cache_mode == "sync":
self.refresh()
return rows.rowcount

def _get_object(
self,
Expand Down Expand Up @@ -1927,14 +1929,9 @@ def apply_permission(
)

def delete_permission(self, name: str, project: str, commit: bool = True):
with self.write_engine.begin() as conn:
stmt = delete(permissions).where(
permissions.c.permission_name == name,
permissions.c.project_id == project,
)
rows = conn.execute(stmt)
if rows.rowcount < 1:
raise PermissionNotFoundException(name, project)
return self._delete_object(
permissions, name, project, "permission_name", PermissionNotFoundException
)

def _list_projects(
self,
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from feast import Field
from feast.data_source import PushSource
from feast.entity import Entity
from feast.errors import ConflictingFeatureViewNames
from feast.errors import ConflictingFeatureViewNames, PermissionNotFoundException
from feast.feature_view import FeatureView
from feast.infra.offline_stores.file_source import FileSource
from feast.infra.registry.sql import (
Expand All @@ -38,6 +38,9 @@
from feast.infra.registry.sql import (
metadata as registry_metadata,
)
from feast.permissions.action import AuthzedAction
from feast.permissions.permission import Permission
from feast.permissions.policy import RoleBasedPolicy
from feast.protos.feast.core.Transformation_pb2 import (
FeatureTransformationV2,
UserDefinedFunctionV2,
Expand Down Expand Up @@ -347,6 +350,37 @@ def test_sql_registry(sqlite_registry):
sqlite_registry.get_entity("test_entity", "test_project")


def test_delete_permission_refreshes_cache(sqlite_registry):
permission = Permission(
name="reader",
types=FeatureView,
policy=RoleBasedPolicy(roles=["reader"]),
actions=[AuthzedAction.DESCRIBE],
)
sqlite_registry.apply_permission(permission, "test_project")
assert [
p.name
for p in sqlite_registry.list_permissions("test_project", allow_cache=True)
] == ["reader"]

sqlite_registry.delete_permission("reader", "test_project")

assert sqlite_registry.list_permissions("test_project", allow_cache=True) == []
with pytest.raises(PermissionNotFoundException):
sqlite_registry.delete_permission("reader", "test_project")


def test_delete_entity_refreshes_cache(sqlite_registry):
sqlite_registry.apply_entity(Entity(name="driver"), "test_project")
assert [
e.name for e in sqlite_registry.list_entities("test_project", allow_cache=True)
] == ["driver"]

sqlite_registry.delete_entity("driver", "test_project")

assert sqlite_registry.list_entities("test_project", allow_cache=True) == []


def _build_feature_view(name: str, entity: Entity, source: FileSource) -> FeatureView:
return FeatureView(
name=name,
Expand Down
Loading

Back | FazBrowse Home | New Git URL