Skip to content

Commit 767f7f8

Browse files
author
Aditya Patil
committed
fix: Bypass registry cache for projects-list endpoint
Signed-off-by: Aditya Patil <adpatil@redhat.com>
1 parent 6bdcf27 commit 767f7f8

2 files changed

Lines changed: 49 additions & 16 deletions

File tree

sdk/python/feast/ui_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def _build_projects_list(
6262
registry_path_template = f"{root_path}/api/v1"
6363

6464
try:
65-
projects = store.registry.list_projects(allow_cache=True)
65+
projects = store.registry.list_projects(allow_cache=False)
6666
for proj in projects:
6767
discovered_projects.append(
6868
{

sdk/python/tests/unit/test_ui_server.py

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,12 @@ def test_catch_all_route(ui_app_with_registry):
148148
# ---------- projects-list.json tests ----------
149149

150150

151-
def _read_projects_list(temp_dir):
152-
"""Read the projects-list.json written by get_app via the mock (ui_dir = temp_dir)."""
153-
projects_file = os.path.join(temp_dir, "projects-list.json")
154-
with open(projects_file) as f:
155-
return json.load(f)
151+
def _get_projects_list(app):
152+
"""Fetch the dynamic projects-list.json endpoint."""
153+
client = TestClient(app)
154+
resp = client.get("/projects-list.json")
155+
assertpy.assert_that(resp.status_code).is_equal_to(EXPECTED_SUCCESS_STATUS)
156+
return resp.json()
156157

157158

158159
def test_projects_list_registry_path(mock_feature_store):
@@ -165,9 +166,9 @@ def test_projects_list_registry_path(mock_feature_store):
165166
_create_mock_ui_files(temp_dir)
166167

167168
with _setup_importlib_mocks(temp_dir):
168-
get_app(mock_feature_store, TEST_PROJECT_NAME)
169+
app = get_app(mock_feature_store, TEST_PROJECT_NAME)
169170

170-
data = _read_projects_list(temp_dir)
171+
data = _get_projects_list(app)
171172
assertpy.assert_that(data["projects"][0]["registryPath"]).is_equal_to("/api/v1")
172173

173174

@@ -181,13 +182,13 @@ def test_projects_list_with_root_path(mock_feature_store):
181182
_create_mock_ui_files(temp_dir)
182183

183184
with _setup_importlib_mocks(temp_dir):
184-
get_app(
185+
app = get_app(
185186
mock_feature_store,
186187
TEST_PROJECT_NAME,
187188
root_path="/feast",
188189
)
189190

190-
data = _read_projects_list(temp_dir)
191+
data = _get_projects_list(app)
191192
assertpy.assert_that(data["projects"][0]["registryPath"]).is_equal_to(
192193
"/feast/api/v1"
193194
)
@@ -206,9 +207,9 @@ def test_projects_list_multiple_projects(mock_feature_store):
206207
_create_mock_ui_files(temp_dir)
207208

208209
with _setup_importlib_mocks(temp_dir):
209-
get_app(mock_feature_store, TEST_PROJECT_NAME)
210+
app = get_app(mock_feature_store, TEST_PROJECT_NAME)
210211

211-
data = _read_projects_list(temp_dir)
212+
data = _get_projects_list(app)
212213
assertpy.assert_that(len(data["projects"])).is_equal_to(3)
213214
assertpy.assert_that(data["projects"][0]["id"]).is_equal_to("all")
214215
assertpy.assert_that(data["projects"][1]["id"]).is_equal_to("project_alpha")
@@ -225,9 +226,9 @@ def test_projects_list_fallback_on_empty(mock_feature_store):
225226
_create_mock_ui_files(temp_dir)
226227

227228
with _setup_importlib_mocks(temp_dir):
228-
get_app(mock_feature_store, TEST_PROJECT_NAME)
229+
app = get_app(mock_feature_store, TEST_PROJECT_NAME)
229230

230-
data = _read_projects_list(temp_dir)
231+
data = _get_projects_list(app)
231232
assertpy.assert_that(len(data["projects"])).is_equal_to(1)
232233
assertpy.assert_that(data["projects"][0]["id"]).is_equal_to(TEST_PROJECT_NAME)
233234

@@ -242,8 +243,40 @@ def test_projects_list_fallback_on_exception(mock_feature_store):
242243
_create_mock_ui_files(temp_dir)
243244

244245
with _setup_importlib_mocks(temp_dir):
245-
get_app(mock_feature_store, TEST_PROJECT_NAME)
246+
app = get_app(mock_feature_store, TEST_PROJECT_NAME)
246247

247-
data = _read_projects_list(temp_dir)
248+
data = _get_projects_list(app)
248249
assertpy.assert_that(len(data["projects"])).is_equal_to(1)
249250
assertpy.assert_that(data["projects"][0]["id"]).is_equal_to(TEST_PROJECT_NAME)
251+
252+
253+
def test_projects_list_dynamic_refresh(mock_feature_store):
254+
"""New projects appear without restarting the server."""
255+
mock_registry = MagicMock()
256+
mock_registry.list_projects.return_value = [
257+
_make_project_mock("picked_elk"),
258+
]
259+
mock_feature_store.registry = mock_registry
260+
261+
with tempfile.TemporaryDirectory() as temp_dir:
262+
_create_mock_ui_files(temp_dir)
263+
264+
with _setup_importlib_mocks(temp_dir):
265+
app = get_app(mock_feature_store, TEST_PROJECT_NAME)
266+
267+
client = TestClient(app)
268+
269+
data = client.get("/projects-list.json").json()
270+
assertpy.assert_that(len(data["projects"])).is_equal_to(1)
271+
assertpy.assert_that(data["projects"][0]["id"]).is_equal_to("picked_elk")
272+
273+
mock_registry.list_projects.return_value = [
274+
_make_project_mock("picked_elk"),
275+
_make_project_mock("picked_elk2"),
276+
]
277+
278+
data = client.get("/projects-list.json").json()
279+
assertpy.assert_that(len(data["projects"])).is_equal_to(3)
280+
assertpy.assert_that(data["projects"][0]["id"]).is_equal_to("all")
281+
assertpy.assert_that(data["projects"][1]["id"]).is_equal_to("picked_elk")
282+
assertpy.assert_that(data["projects"][2]["id"]).is_equal_to("picked_elk2")

0 commit comments

Comments
 (0)