Skip to content

Commit d7cb4d0

Browse files
YHC66ntkathole
authored andcommitted
fix: Don't return from finally blocks in REST registry helpers
The REST registry list helpers and _validate_projects returned from a finally block. That silently swallows BaseExceptions such as KeyboardInterrupt and SystemExit (they turn into an empty result with no error message), and on Python 3.14 it emits a SyntaxWarning (PEP 765) when the modules are compiled. Move the returns after the try/except. Regular exceptions are still caught and reported through the error message as before. Signed-off-by: Yihang Chen <[email protected]>
1 parent 4b81d18 commit d7cb4d0

3 files changed

Lines changed: 64 additions & 22 deletions

File tree

‎sdk/python/feast/api/registry/rest/rest_utils.py‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ def get_all_project_resources(
568568
err_msg = f"Error getting resources for project '{project}'"
569569
errors.append(err_msg)
570570
logger.error(f"{err_msg}: {e}")
571-
finally:
572-
return resources, pagination, errors
571+
572+
return resources, pagination, errors
573573

574574

575575
def filter_search_results_and_match_score(
@@ -699,8 +699,8 @@ def list_entities(
699699
except Exception as e:
700700
err_msg = f"Error searching entities in project '{project}'"
701701
logger.error(f"{err_msg}: {e}")
702-
finally:
703-
return entities, pagination, err_msg
702+
703+
return entities, pagination, err_msg
704704

705705

706706
def list_feature_views(
@@ -745,8 +745,8 @@ def list_feature_views(
745745
except Exception as e:
746746
err_msg = f"Error searching feature views in project '{project}'"
747747
logger.error(f"{err_msg}: {e}")
748-
finally:
749-
return feature_views, pagination, err_msg
748+
749+
return feature_views, pagination, err_msg
750750

751751

752752
def list_feature_services(
@@ -790,8 +790,8 @@ def list_feature_services(
790790
except Exception as e:
791791
err_msg = f"Error searching feature services in project '{project}'"
792792
logger.error(f"{err_msg}: {e}")
793-
finally:
794-
return feature_services, pagination, err_msg
793+
794+
return feature_services, pagination, err_msg
795795

796796

797797
def list_data_sources(
@@ -835,8 +835,8 @@ def list_data_sources(
835835
except Exception as e:
836836
err_msg = f"Error searching data sources in project '{project}'"
837837
logger.error(f"{err_msg}: {e}")
838-
finally:
839-
return data_sources, pagination, err_msg
838+
839+
return data_sources, pagination, err_msg
840840

841841

842842
def list_saved_datasets(
@@ -880,8 +880,8 @@ def list_saved_datasets(
880880
except Exception as e:
881881
err_msg = f"Error searching saved datasets in project '{project}'"
882882
logger.error(f"{err_msg}: {e}")
883-
finally:
884-
return saved_datasets, pagination, err_msg
883+
884+
return saved_datasets, pagination, err_msg
885885

886886

887887
def list_features(
@@ -921,8 +921,8 @@ def list_features(
921921
except Exception as e:
922922
err_msg = f"Error searching features in project '{project}'"
923923
logger.error(f"{err_msg}: {e}")
924-
finally:
925-
return features, pagination, err_msg
924+
925+
return features, pagination, err_msg
926926

927927

928928
def list_label_views(
@@ -962,8 +962,8 @@ def list_label_views(
962962
except Exception as e:
963963
err_msg = f"Error searching label views in project '{project}'"
964964
logger.error(f"{err_msg}: {e}")
965-
finally:
966-
return label_views, pagination, err_msg
965+
966+
return label_views, pagination, err_msg
967967

968968

969969
def list_labels(
@@ -1002,8 +1002,8 @@ def list_labels(
10021002
except Exception as e:
10031003
err_msg = f"Error searching labels in project '{project}'"
10041004
logger.error(f"{err_msg}: {e}")
1005-
finally:
1006-
return labels, pagination, err_msg
1005+
1006+
return labels, pagination, err_msg
10071007

10081008

10091009
def list_all_projects(
@@ -1043,5 +1043,5 @@ def list_all_projects(
10431043
except Exception as e:
10441044
err_msg = "Error searching all projects"
10451045
logger.error(f"{err_msg}: {e}")
1046-
finally:
1047-
return projects, pagination, err_msg
1046+
1047+
return projects, pagination, err_msg

‎sdk/python/feast/api/registry/rest/search.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ def _validate_projects(
322322
err_msg = "Error getting projects"
323323
logger.error(f"{err_msg}: {e}")
324324

325-
finally:
326-
return list(set(projects_to_search)), err_msg
325+
return list(set(projects_to_search)), err_msg
327326

328327

329328
def _remove_tags_from_results(results: List[Dict]) -> List[Dict]:

‎sdk/python/tests/unit/api/test_api_rest_registry.py‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import ast
22
import os
33
import tempfile
4+
from unittest.mock import MagicMock, patch
45

56
import pandas as pd
67
import pytest
78
from fastapi.testclient import TestClient
89

910
from feast import Entity, FeatureService, FeatureStore, FeatureView, Field, FileSource
11+
from feast.api.registry.rest import rest_utils, search
1012
from feast.api.registry.rest.rest_registry_server import RestRegistryServer
1113
from feast.data_source import RequestSource
1214
from feast.infra.offline_stores.file_source import SavedDatasetFileStorage
@@ -2328,3 +2330,44 @@ def test_registry_refresh_via_rest_error():
23282330
assert response.status_code == 500
23292331

23302332
tmp_dir.cleanup()
2333+
2334+
2335+
@pytest.mark.parametrize(
2336+
"list_fn",
2337+
[
2338+
rest_utils.list_entities,
2339+
rest_utils.list_feature_views,
2340+
rest_utils.list_feature_services,
2341+
rest_utils.list_data_sources,
2342+
rest_utils.list_saved_datasets,
2343+
rest_utils.list_features,
2344+
rest_utils.list_label_views,
2345+
rest_utils.list_labels,
2346+
],
2347+
)
2348+
def test_list_helpers_do_not_swallow_base_exceptions(list_fn):
2349+
# Regular errors are reported through err_msg, but KeyboardInterrupt /
2350+
# SystemExit must propagate instead of turning into an empty result.
2351+
with patch.object(rest_utils, "grpc_call", side_effect=KeyboardInterrupt):
2352+
with pytest.raises(KeyboardInterrupt):
2353+
list_fn(grpc_handler=MagicMock(), project="p", allow_cache=True)
2354+
2355+
2356+
def test_list_all_projects_does_not_swallow_base_exceptions():
2357+
with patch.object(rest_utils, "grpc_call", side_effect=KeyboardInterrupt):
2358+
with pytest.raises(KeyboardInterrupt):
2359+
rest_utils.list_all_projects(grpc_handler=MagicMock(), allow_cache=True)
2360+
2361+
2362+
def test_get_all_project_resources_does_not_swallow_base_exceptions():
2363+
with patch.object(rest_utils, "list_entities", side_effect=KeyboardInterrupt):
2364+
with pytest.raises(KeyboardInterrupt):
2365+
rest_utils.get_all_project_resources(
2366+
grpc_handler=MagicMock(), project="p", allow_cache=True
2367+
)
2368+
2369+
2370+
def test_validate_projects_does_not_swallow_base_exceptions():
2371+
with patch.object(search, "list_all_projects", side_effect=KeyboardInterrupt):
2372+
with pytest.raises(KeyboardInterrupt):
2373+
search._validate_projects(["p"], MagicMock(), allow_cache=True)

0 commit comments

Comments
 (0)