From d2d66bd9524f37c1593346af958bd90670f5ec84 Mon Sep 17 00:00:00 2001 From: tushar-mahalya Date: Tue, 24 Nov 2026 21:04:26 +0530 Subject: [PATCH 1/2] fix: Clear a project's infra from the file registry when the project is deleted `feast teardown` removes the online store but the file registry kept the project's infra objects. The next `feast apply` diffed the desired infra against that stale record, reported "No changes to infrastructure" and never recreated the sqlite tables, so `feast materialize` failed with "no such table". The SQL registry already deletes the managed infra row in delete_project; do the same for the file registry, limited to objects named after the deleted project. Signed-off-by: tushar-mahalya --- sdk/python/feast/infra/registry/registry.py | 14 +++++ .../unit/infra/registry/test_file_registry.py | 23 +++++++ .../test_local_feature_store.py | 62 +++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/sdk/python/feast/infra/registry/registry.py b/sdk/python/feast/infra/registry/registry.py index baa8620140e..631d16d9232 100644 --- a/sdk/python/feast/infra/registry/registry.py +++ b/sdk/python/feast/infra/registry/registry.py @@ -1727,8 +1727,22 @@ def delete_project( list_permissions = self.list_permissions(name) for permission in list_permissions: self.delete_permission(permission.name, name) + self._delete_project_infra(name) del self.cached_registry_proto.projects[idx] if commit: self.commit() return raise ProjectNotFoundException(name) + + def _delete_project_infra(self, project: str): + assert self.cached_registry_proto + project_prefix = f"{project}_" + infra_objects = self.cached_registry_proto.infra.infra_objects + kept = [] + for infra_object in infra_objects: + kind = infra_object.WhichOneof("infra_object") + name = getattr(getattr(infra_object, kind), "name", "") if kind else "" + if not name.startswith(project_prefix): + kept.append(infra_object) + del infra_objects[:] + infra_objects.extend(kept) diff --git a/sdk/python/tests/unit/infra/registry/test_file_registry.py b/sdk/python/tests/unit/infra/registry/test_file_registry.py index 8e771d380cf..751b9bcb7b3 100644 --- a/sdk/python/tests/unit/infra/registry/test_file_registry.py +++ b/sdk/python/tests/unit/infra/registry/test_file_registry.py @@ -9,8 +9,11 @@ from feast.entity import Entity from feast.errors import ConflictingFeatureViewNames from feast.feature_view import FeatureView +from feast.infra.infra_object import Infra from feast.infra.offline_stores.file_source import FileSource +from feast.infra.online_stores.sqlite import SqliteTable from feast.infra.registry.registry import Registry +from feast.project import Project from feast.repo_config import RegistryConfig from feast.stream_feature_view import StreamFeatureView from feast.types import Float32 @@ -185,3 +188,23 @@ def test_cross_project_name_does_not_conflict_batch_vs_stream(file_registry): ) # Must not raise — same name, different project, different type. file_registry.apply_feature_view(stream_view, "project_b") + + +def test_delete_project_removes_only_its_infra_objects(file_registry, tmp_path): + online_store_path = str(tmp_path / "online.db") + infra = Infra( + infra_objects=[ + SqliteTable(path=online_store_path, name="project_a_driver_stats"), + SqliteTable(path=online_store_path, name="project_b_driver_stats"), + ] + ) + file_registry.apply_project(Project(name="project_a")) + file_registry.apply_project(Project(name="project_b")) + file_registry.update_infra(infra, "project_a") + + file_registry.delete_project("project_a") + + remaining = file_registry.get_infra("project_b").infra_objects + assert [infra_object.name for infra_object in remaining] == [ + "project_b_driver_stats" + ] diff --git a/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py b/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py index 64872fcd353..24fc4a5e37b 100644 --- a/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py +++ b/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py @@ -1,3 +1,4 @@ +import sqlite3 from datetime import datetime, timedelta, timezone from tempfile import mkstemp from unittest.mock import AsyncMock, Mock, patch @@ -23,7 +24,9 @@ from feast.permissions.action import AuthzedAction from feast.permissions.permission import Permission from feast.permissions.policy import RoleBasedPolicy +from feast.project import Project from feast.repo_config import RegistryConfig, RepoConfig +from feast.repo_contents import RepoContents from feast.saved_dataset import SavedDataset from feast.stream_feature_view import stream_feature_view from feast.transformation.pandas_transformation import PandasTransformation @@ -1006,6 +1009,65 @@ def feature_store_with_local_registry(): ) +def test_apply_after_teardown_recreates_online_store_tables(tmp_path): + online_store_path = tmp_path / "online_store.db" + config = RepoConfig( + registry=str(tmp_path / "registry.db"), + project="teardown_apply", + provider="local", + online_store=SqliteOnlineStoreConfig(path=str(online_store_path)), + entity_key_serialization_version=3, + ) + store = FeatureStore(config=config) + entity = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64) + feature_view = FeatureView( + name="driver_stats", + entities=[entity], + schema=[Field(name="conv_rate", dtype=Float32)], + source=FileSource( + path=str(tmp_path / "driver_stats.parquet"), + timestamp_field="event_timestamp", + ), + ) + + def online_store_tables() -> set: + conn = sqlite3.connect(online_store_path) + try: + return { + row[0] + for row in conn.execute("SELECT name FROM sqlite_master").fetchall() + } + finally: + conn.close() + + def plan_and_apply(store: FeatureStore) -> None: + repo_contents = RepoContents( + projects=[Project(name=config.project)], + data_sources=[feature_view.batch_source], + feature_views=[feature_view], + on_demand_feature_views=[], + stream_feature_views=[], + label_views=[], + entities=[entity], + feature_services=[], + permissions=[], + ) + registry_diff, infra_diff, new_infra = store.plan(repo_contents) + store._apply_diffs(registry_diff, infra_diff, new_infra) + + plan_and_apply(store) + assert "teardown_apply_driver_stats" in online_store_tables() + + store.teardown() + assert not online_store_path.exists() + + store = FeatureStore(config=config) + plan_and_apply(store) + assert "teardown_apply_driver_stats" in online_store_tables() + + store.teardown() + + @pytest.mark.parametrize( "test_feature_store", [lazy_fixture("feature_store_with_local_registry")], From d7c184c433ce06a8a2304909ac726be44d47aa2c Mon Sep 17 00:00:00 2001 From: tushar-mahalya Date: Tue, 24 Nov 2026 21:39:52 +0530 Subject: [PATCH 2/2] fix: Clear tracked infra on teardown instead of on project deletion Deleting a project from the file registry also removed its infra records, but `feast projects delete` only removes registry metadata and leaves the online store tables in place. A later apply could then no longer drop obsolete tables, because diff_infra_protos only deletes objects that are both recorded and no longer desired. The prefix match could also remove another project's records (`a` vs `a_b`). Revert the change to Registry.delete_project and clear the tracked infra in FeatureStore.teardown instead, right after the provider has torn the infra down and before the projects are deleted so the registry does not re-create the project. SQL registries already drop the managed infra row in delete_project. Signed-off-by: tushar-mahalya --- sdk/python/feast/feature_store.py | 7 ++ sdk/python/feast/infra/registry/registry.py | 14 --- .../unit/infra/registry/test_file_registry.py | 23 ---- .../test_local_feature_store.py | 109 ++++++++++++------ 4 files changed, 79 insertions(+), 74 deletions(-) diff --git a/sdk/python/feast/feature_store.py b/sdk/python/feast/feature_store.py index 49fa6ebf43e..3a219c47d37 100644 --- a/sdk/python/feast/feature_store.py +++ b/sdk/python/feast/feature_store.py @@ -1998,6 +1998,13 @@ def teardown(self): self._get_provider().teardown_infra(self.project, tables, entities) # type: ignore[arg-type] + # The infra objects tracked in the registry no longer exist. Clear them + # while the project is still registered (so the registry does not + # re-create it), otherwise the next apply diffs against stale infra and + # skips re-creating the tables. SQL registries drop this record in + # delete_project; the file registry keeps it in the registry proto. + self.registry.update_infra(Infra(), self.project, commit=True) + for project in self.list_projects(): self.registry.delete_project(project.name) diff --git a/sdk/python/feast/infra/registry/registry.py b/sdk/python/feast/infra/registry/registry.py index 631d16d9232..baa8620140e 100644 --- a/sdk/python/feast/infra/registry/registry.py +++ b/sdk/python/feast/infra/registry/registry.py @@ -1727,22 +1727,8 @@ def delete_project( list_permissions = self.list_permissions(name) for permission in list_permissions: self.delete_permission(permission.name, name) - self._delete_project_infra(name) del self.cached_registry_proto.projects[idx] if commit: self.commit() return raise ProjectNotFoundException(name) - - def _delete_project_infra(self, project: str): - assert self.cached_registry_proto - project_prefix = f"{project}_" - infra_objects = self.cached_registry_proto.infra.infra_objects - kept = [] - for infra_object in infra_objects: - kind = infra_object.WhichOneof("infra_object") - name = getattr(getattr(infra_object, kind), "name", "") if kind else "" - if not name.startswith(project_prefix): - kept.append(infra_object) - del infra_objects[:] - infra_objects.extend(kept) diff --git a/sdk/python/tests/unit/infra/registry/test_file_registry.py b/sdk/python/tests/unit/infra/registry/test_file_registry.py index 751b9bcb7b3..8e771d380cf 100644 --- a/sdk/python/tests/unit/infra/registry/test_file_registry.py +++ b/sdk/python/tests/unit/infra/registry/test_file_registry.py @@ -9,11 +9,8 @@ from feast.entity import Entity from feast.errors import ConflictingFeatureViewNames from feast.feature_view import FeatureView -from feast.infra.infra_object import Infra from feast.infra.offline_stores.file_source import FileSource -from feast.infra.online_stores.sqlite import SqliteTable from feast.infra.registry.registry import Registry -from feast.project import Project from feast.repo_config import RegistryConfig from feast.stream_feature_view import StreamFeatureView from feast.types import Float32 @@ -188,23 +185,3 @@ def test_cross_project_name_does_not_conflict_batch_vs_stream(file_registry): ) # Must not raise — same name, different project, different type. file_registry.apply_feature_view(stream_view, "project_b") - - -def test_delete_project_removes_only_its_infra_objects(file_registry, tmp_path): - online_store_path = str(tmp_path / "online.db") - infra = Infra( - infra_objects=[ - SqliteTable(path=online_store_path, name="project_a_driver_stats"), - SqliteTable(path=online_store_path, name="project_b_driver_stats"), - ] - ) - file_registry.apply_project(Project(name="project_a")) - file_registry.apply_project(Project(name="project_b")) - file_registry.update_infra(infra, "project_a") - - file_registry.delete_project("project_a") - - remaining = file_registry.get_infra("project_b").infra_objects - assert [infra_object.name for infra_object in remaining] == [ - "project_b_driver_stats" - ] diff --git a/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py b/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py index 24fc4a5e37b..01985ae3109 100644 --- a/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py +++ b/sdk/python/tests/unit/local_feast_tests/test_local_feature_store.py @@ -1009,19 +1009,46 @@ def feature_store_with_local_registry(): ) -def test_apply_after_teardown_recreates_online_store_tables(tmp_path): - online_store_path = tmp_path / "online_store.db" - config = RepoConfig( +def _sqlite_tables(path) -> set: + conn = sqlite3.connect(path) + try: + return { + row[0] for row in conn.execute("SELECT name FROM sqlite_master").fetchall() + } + finally: + conn.close() + + +def _sqlite_store_config(tmp_path, project: str) -> RepoConfig: + return RepoConfig( registry=str(tmp_path / "registry.db"), - project="teardown_apply", + project=project, provider="local", - online_store=SqliteOnlineStoreConfig(path=str(online_store_path)), + online_store=SqliteOnlineStoreConfig(path=str(tmp_path / "online_store.db")), entity_key_serialization_version=3, ) - store = FeatureStore(config=config) - entity = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64) - feature_view = FeatureView( - name="driver_stats", + + +def _plan_and_apply(store: FeatureStore, entity: Entity, feature_views) -> None: + """Applies like `feast apply` does: plan against the registry, then apply the diffs.""" + repo_contents = RepoContents( + projects=[Project(name=store.project)], + data_sources=[fv.batch_source for fv in feature_views], + feature_views=list(feature_views), + on_demand_feature_views=[], + stream_feature_views=[], + label_views=[], + entities=[entity], + feature_services=[], + permissions=[], + ) + registry_diff, infra_diff, new_infra = store.plan(repo_contents) + store._apply_diffs(registry_diff, infra_diff, new_infra) + + +def _driver_stats_view(tmp_path, entity: Entity, name: str) -> FeatureView: + return FeatureView( + name=name, entities=[entity], schema=[Field(name="conv_rate", dtype=Float32)], source=FileSource( @@ -1030,40 +1057,48 @@ def test_apply_after_teardown_recreates_online_store_tables(tmp_path): ), ) - def online_store_tables() -> set: - conn = sqlite3.connect(online_store_path) - try: - return { - row[0] - for row in conn.execute("SELECT name FROM sqlite_master").fetchall() - } - finally: - conn.close() - - def plan_and_apply(store: FeatureStore) -> None: - repo_contents = RepoContents( - projects=[Project(name=config.project)], - data_sources=[feature_view.batch_source], - feature_views=[feature_view], - on_demand_feature_views=[], - stream_feature_views=[], - label_views=[], - entities=[entity], - feature_services=[], - permissions=[], - ) - registry_diff, infra_diff, new_infra = store.plan(repo_contents) - store._apply_diffs(registry_diff, infra_diff, new_infra) - plan_and_apply(store) - assert "teardown_apply_driver_stats" in online_store_tables() +def test_apply_after_teardown_recreates_online_store_tables(tmp_path): + config = _sqlite_store_config(tmp_path, "teardown_apply") + online_store_path = tmp_path / "online_store.db" + entity = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64) + feature_view = _driver_stats_view(tmp_path, entity, "driver_stats") + + store = FeatureStore(config=config) + _plan_and_apply(store, entity, [feature_view]) + assert "teardown_apply_driver_stats" in _sqlite_tables(online_store_path) store.teardown() assert not online_store_path.exists() store = FeatureStore(config=config) - plan_and_apply(store) - assert "teardown_apply_driver_stats" in online_store_tables() + _plan_and_apply(store, entity, [feature_view]) + assert "teardown_apply_driver_stats" in _sqlite_tables(online_store_path) + + store.teardown() + + +def test_registry_only_project_delete_keeps_tracked_infra(tmp_path): + """`feast projects delete` only deletes registry metadata, not online store + tables, so the tracked infra must survive it: a later apply of a renamed view + still has to drop the obsolete table.""" + config = _sqlite_store_config(tmp_path, "projects_delete") + online_store_path = tmp_path / "online_store.db" + entity = Entity(name="driver", join_keys=["driver_id"], value_type=ValueType.INT64) + + store = FeatureStore(config=config) + _plan_and_apply(store, entity, [_driver_stats_view(tmp_path, entity, "old_stats")]) + assert "projects_delete_old_stats" in _sqlite_tables(online_store_path) + + # Same as `feast projects delete`: registry metadata only, no teardown_infra. + store.registry.delete_project("projects_delete") + + store = FeatureStore(config=config) + _plan_and_apply(store, entity, [_driver_stats_view(tmp_path, entity, "new_stats")]) + + tables = _sqlite_tables(online_store_path) + assert "projects_delete_new_stats" in tables + assert "projects_delete_old_stats" not in tables store.teardown()