Skip to content

Commit 4018e7b

Browse files
Clean up document endpoints
Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
1 parent be1b522 commit 4018e7b

File tree

3 files changed

+0
-159
lines changed

3 files changed

+0
-159
lines changed

sdk/python/feast/feature_server.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,6 @@ class ChatRequest(BaseModel):
129129
messages: List[ChatMessage]
130130

131131

132-
class ReadDocumentRequest(BaseModel):
133-
file_path: str
134-
135-
136-
class SaveDocumentRequest(BaseModel):
137-
file_path: str
138-
data: dict
139-
140-
141132
async def _get_features(
142133
request: Union[GetOnlineFeaturesRequest, GetOnlineDocumentsRequest],
143134
store: "feast.FeatureStore",
@@ -542,42 +533,6 @@ async def chat(request: ChatRequest):
542533
# For now, just return dummy text
543534
return {"response": "This is a dummy response from the Feast feature server."}
544535

545-
@app.post("/read-document", dependencies=[Depends(inject_user_details)])
546-
async def read_document_endpoint(request: ReadDocumentRequest):
547-
try:
548-
import os
549-
550-
if not os.path.exists(request.file_path):
551-
return {"error": f"File not found: {request.file_path}"}
552-
553-
with open(request.file_path, "r", encoding="utf-8") as file:
554-
content = file.read()
555-
556-
return {"content": content, "file_path": request.file_path}
557-
except Exception as e:
558-
return {"error": str(e)}
559-
560-
@app.post("/save-document", dependencies=[Depends(inject_user_details)])
561-
async def save_document_endpoint(request: SaveDocumentRequest):
562-
try:
563-
import json
564-
import os
565-
from pathlib import Path
566-
567-
file_path = Path(request.file_path).resolve()
568-
if not str(file_path).startswith(os.getcwd()):
569-
return {"error": "Invalid file path"}
570-
571-
base_name = file_path.stem
572-
labels_file = file_path.parent / f"{base_name}-labels.json"
573-
574-
with open(labels_file, "w", encoding="utf-8") as file:
575-
json.dump(request.data, file, indent=2, ensure_ascii=False)
576-
577-
return {"success": True, "saved_to": str(labels_file)}
578-
except Exception as e:
579-
return {"error": str(e)}
580-
581536
@app.get("/chat")
582537
async def chat_ui():
583538
# Serve the chat UI

sdk/python/feast/ui_server.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@
77
from fastapi import FastAPI, Response, status
88
from fastapi.middleware.cors import CORSMiddleware
99
from fastapi.staticfiles import StaticFiles
10-
from pydantic import BaseModel
1110

1211
import feast
1312

1413

15-
class SaveDocumentRequest(BaseModel):
16-
file_path: str
17-
data: dict
18-
19-
2014
def get_app(
2115
store: "feast.FeatureStore",
2216
project_id: str,
@@ -121,26 +115,6 @@ def health():
121115
else Response(status_code=status.HTTP_503_SERVICE_UNAVAILABLE)
122116
)
123117

124-
@app.post("/save-document")
125-
async def save_document_endpoint(request: SaveDocumentRequest):
126-
try:
127-
import os
128-
from pathlib import Path
129-
130-
file_path = Path(request.file_path).resolve()
131-
if not str(file_path).startswith(os.getcwd()):
132-
return {"error": "Invalid file path"}
133-
134-
base_name = file_path.stem
135-
labels_file = file_path.parent / f"{base_name}-labels.json"
136-
137-
with open(labels_file, "w", encoding="utf-8") as file:
138-
json.dump(request.data, file, indent=2, ensure_ascii=False)
139-
140-
return {"success": True, "saved_to": str(labels_file)}
141-
except Exception as e:
142-
return {"error": str(e)}
143-
144118
# For all other paths (such as paths that would otherwise be handled by react router), pass to React
145119
@app.api_route("/p/{path_name:path}", methods=["GET"])
146120
def catch_all():

sdk/python/tests/unit/test_ui_server.py

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -161,94 +161,6 @@ def test_registry_endpoint_with_none_data(ui_app_without_registry):
161161
assertpy.assert_that(response.status_code).is_equal_to(EXPECTED_ERROR_STATUS)
162162

163163

164-
def test_save_document_endpoint_success(ui_app_with_registry):
165-
"""Test the save document endpoint successfully saves data to a labels file.
166-
167-
This test verifies that the /save-document endpoint correctly processes
168-
a valid request, creates a labels file, and returns success confirmation.
169-
"""
170-
client = TestClient(ui_app_with_registry)
171-
172-
# Create a temporary file in the current working directory for testing
173-
with tempfile.NamedTemporaryFile(
174-
mode="w", suffix=".py", delete=False, dir=os.getcwd()
175-
) as f:
176-
test_file_path = f.name
177-
f.write("# Test file content")
178-
179-
try:
180-
request_data = {
181-
"file_path": test_file_path,
182-
"data": {"test": "data", "key": "value"},
183-
}
184-
185-
response = client.post("/save-document", json=request_data)
186-
assertpy.assert_that(response.status_code).is_equal_to(EXPECTED_SUCCESS_STATUS)
187-
188-
response_data = response.json()
189-
assertpy.assert_that(response_data["success"]).is_true()
190-
assertpy.assert_that(response_data).contains_key("saved_to")
191-
192-
# Verify the file was created
193-
labels_file = response_data["saved_to"]
194-
assertpy.assert_that(os.path.exists(labels_file)).is_true()
195-
196-
with open(labels_file, "r") as f:
197-
saved_data = json.load(f)
198-
assertpy.assert_that(saved_data).is_equal_to(request_data["data"])
199-
200-
finally:
201-
# Cleanup
202-
if os.path.exists(test_file_path):
203-
os.unlink(test_file_path)
204-
labels_file = test_file_path.replace(".py", "-labels.json")
205-
if os.path.exists(labels_file):
206-
os.unlink(labels_file)
207-
208-
209-
def test_save_document_endpoint_invalid_path(ui_app_with_registry):
210-
"""Test the save document endpoint returns error for invalid file path.
211-
212-
This test verifies that the /save-document endpoint correctly rejects
213-
file paths that are outside the current working directory for security.
214-
"""
215-
client = TestClient(ui_app_with_registry)
216-
217-
request_data = {
218-
"file_path": "/invalid/absolute/path/outside/workspace.py",
219-
"data": {"test": "data"},
220-
}
221-
222-
response = client.post("/save-document", json=request_data)
223-
assertpy.assert_that(response.status_code).is_equal_to(EXPECTED_SUCCESS_STATUS)
224-
225-
response_data = response.json()
226-
assertpy.assert_that(response_data).contains_key("error")
227-
assertpy.assert_that(response_data["error"]).contains("Invalid file path")
228-
229-
230-
def test_save_document_endpoint_exception_handling(ui_app_with_registry):
231-
"""Test the save document endpoint handles exceptions gracefully.
232-
233-
This test verifies that the /save-document endpoint properly catches
234-
and returns error responses when exceptions occur during processing.
235-
"""
236-
client = TestClient(ui_app_with_registry)
237-
238-
# Test with a file path outside the current working directory (will cause an exception)
239-
request_data = {
240-
"file_path": "/invalid/absolute/path/outside/workspace.py",
241-
"data": {"test": "data"},
242-
}
243-
244-
response = client.post("/save-document", json=request_data)
245-
assertpy.assert_that(response.status_code).is_equal_to(EXPECTED_SUCCESS_STATUS)
246-
247-
response_data = response.json()
248-
assertpy.assert_that(response_data).contains_key("error")
249-
assertpy.assert_that(response_data["error"]).contains("Invalid file path")
250-
251-
252164
@pytest.mark.parametrize(
253165
"registry_available,expected_status",
254166
[(True, EXPECTED_SUCCESS_STATUS), (False, EXPECTED_ERROR_STATUS)],

0 commit comments

Comments
 (0)