Skip to content

Commit 033dfe2

Browse files
committed
fix: Fixed registry cache init
Signed-off-by: ntkathole <[email protected]>
1 parent bb0308c commit 033dfe2

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
lines changed

sdk/python/feast/infra/registry/caching_registry.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,15 @@ def _refresh_cached_registry_if_necessary(self):
435435
if self.cache_mode == "sync":
436436

437437
def is_cache_expired():
438-
if self.cached_registry_proto == RegistryProto():
439-
if self.cached_registry_proto_ttl.total_seconds() == 0:
440-
return False
441-
else:
442-
return True
443-
444-
# Cache is expired if it's None or creation time is None
445438
if (
446439
self.cached_registry_proto is None
447-
or not hasattr(self, "cached_registry_proto_created")
440+
or self.cached_registry_proto == RegistryProto()
441+
):
442+
return True
443+
444+
# Cache is expired if creation time is None
445+
if (
446+
not hasattr(self, "cached_registry_proto_created")
448447
or self.cached_registry_proto_created is None
449448
):
450449
return True

sdk/python/feast/infra/registry/snowflake.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@ def _apply_object(
404404
if not self.purge_feast_metadata:
405405
self._set_last_updated_metadata(update_datetime, project)
406406

407-
self.refresh()
408-
409407
def apply_permission(
410408
self, permission: Permission, project: str, commit: bool = True
411409
):
@@ -494,7 +492,6 @@ def _delete_object(
494492
raise not_found_exception(name, project)
495493
self._set_last_updated_metadata(_utc_now(), project)
496494

497-
self.refresh()
498495
return cursor.rowcount
499496

500497
def delete_permission(self, name: str, project: str, commit: bool = True):
@@ -1128,6 +1125,18 @@ def process_project(project: Project):
11281125
project_name = project.name
11291126
last_updated_timestamp = project.last_updated_timestamp
11301127

1128+
try:
1129+
cached_project = self.get_project(project_name, True)
1130+
except ProjectObjectNotFoundException:
1131+
cached_project = None
1132+
1133+
allow_cache = False
1134+
1135+
if cached_project is not None:
1136+
allow_cache = (
1137+
last_updated_timestamp <= cached_project.last_updated_timestamp
1138+
)
1139+
11311140
r.projects.extend([project.to_proto()])
11321141
last_updated_timestamps.append(last_updated_timestamp)
11331142

@@ -1142,7 +1151,7 @@ def process_project(project: Project):
11421151
(self.list_validation_references, r.validation_references),
11431152
(self.list_permissions, r.permissions),
11441153
]:
1145-
objs: List[Any] = lister(project_name, allow_cache=False) # type: ignore
1154+
objs: List[Any] = lister(project_name, allow_cache) # type: ignore
11461155
if objs:
11471156
obj_protos = [obj.to_proto() for obj in objs]
11481157
for obj_proto in obj_protos:

sdk/python/tests/unit/infra/registry/test_registry.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,6 @@ def test_empty_cache_refresh_with_ttl(registry):
205205
mock_refresh.assert_called_once()
206206

207207

208-
def test_empty_cache_no_refresh_with_infinite_ttl(registry):
209-
"""Test that empty cache is not refreshed when TTL = 0 (infinite)"""
210-
# Set up empty cache with TTL = 0 (infinite)
211-
registry.cached_registry_proto = RegistryProto()
212-
registry.cached_registry_proto_created = datetime.now(timezone.utc)
213-
registry.cached_registry_proto_ttl = timedelta(seconds=0) # TTL = 0 (infinite)
214-
215-
# Mock refresh to check if it's called
216-
with patch.object(
217-
CachingRegistry, "refresh", wraps=registry.refresh
218-
) as mock_refresh:
219-
registry._refresh_cached_registry_if_necessary()
220-
# Should not refresh because TTL = 0 (infinite)
221-
mock_refresh.assert_not_called()
222-
223-
224208
def test_concurrent_cache_refresh_race_condition(registry):
225209
"""Test that concurrent requests don't skip cache refresh when cache is expired"""
226210
import threading

0 commit comments

Comments
 (0)