Skip to content

Commit

Permalink
fix: Return 422 on bad push source name (feast-dev#3214)
Browse files Browse the repository at this point in the history
* return 422 on bad push source name

Signed-off-by: Rob Howley <rhowley@seatgeek.com>

* fix: cant send empty df

Signed-off-by: Rob Howley <rhowley@seatgeek.com>

* return 422 on bad push source name

Signed-off-by: Rob Howley <rhowley@seatgeek.com>

* fix: cant send empty df

Signed-off-by: Rob Howley <rhowley@seatgeek.com>

* fix: json.dumps the body in the post 🤦

Signed-off-by: Rob Howley <rhowley@seatgeek.com>

Signed-off-by: Rob Howley <rhowley@seatgeek.com>
Co-authored-by: Rob Howley <rhowley@seatgeek.com>
  • Loading branch information
robhowley and Rob Howley authored Sep 29, 2022
1 parent 97b7ab9 commit b851e01
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sdk/python/feast/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,8 @@ def __init__(self):
super().__init__(
"The entity dataframe specified does not have the timestamp field as a datetime."
)


class PushSourceNotFoundException(Exception):
def __init__(self, push_source_name: str):
super().__init__(f"Unable to find push source '{push_source_name}'.")
6 changes: 6 additions & 0 deletions sdk/python/feast/feature_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import feast
from feast import proto_json
from feast.data_source import PushMode
from feast.errors import PushSourceNotFoundException
from feast.protos.feast.serving.ServingService_pb2 import GetOnlineFeaturesRequest


Expand Down Expand Up @@ -98,6 +99,11 @@ def push(body=Depends(get_body)):
allow_registry_cache=request.allow_registry_cache,
to=to,
)
except PushSourceNotFoundException as e:
# Print the original exception on the server side
logger.exception(traceback.format_exc())
# Raise HTTPException to return the error message to the client
raise HTTPException(status_code=422, detail=str(e))
except Exception as e:
# Print the original exception on the server side
logger.exception(traceback.format_exc())
Expand Down
4 changes: 4 additions & 0 deletions sdk/python/feast/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
EntityNotFoundException,
FeatureNameCollisionError,
FeatureViewNotFoundException,
PushSourceNotFoundException,
RequestDataNotFoundInEntityDfException,
RequestDataNotFoundInEntityRowsException,
)
Expand Down Expand Up @@ -1445,6 +1446,9 @@ def push(
)
}

if not fvs_with_push_sources:
raise PushSourceNotFoundException(push_source_name)

for fv in fvs_with_push_sources:
if to == PushMode.ONLINE or to == PushMode.ONLINE_AND_OFFLINE:
self.write_to_online_store(
Expand Down
23 changes: 23 additions & 0 deletions sdk/python/tests/integration/e2e/test_python_feature_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ def test_push(python_fs_client):
) == [initial_temp * 100]


@pytest.mark.integration
@pytest.mark.universal_online_stores
def test_push_source_does_not_exist(python_fs_client):
initial_temp = _get_temperatures_from_feature_server(
python_fs_client, location_ids=[1]
)[0]
response = python_fs_client.post(
"/push",
data=json.dumps(
{
"push_source_name": "push_source_does_not_exist",
"df": {
"location_id": [1],
"temperature": [initial_temp * 100],
"event_timestamp": [str(datetime.utcnow())],
"created": [str(datetime.utcnow())],
},
}
),
)
assert response.status_code == 422


def _get_temperatures_from_feature_server(client, location_ids: List[int]):
get_request_data = {
"features": ["pushable_location_stats:temperature"],
Expand Down

0 comments on commit b851e01

Please sign in to comment.