feat(ml): add date range validation to POST /predict/batch
- Parse start_date and end_date as datetime objects - Return HTTP 400 if end_date is before start_date - Return HTTP 400 if date range exceeds 365 days (1 year) Closes task 5.4 in code-review-fix tasks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b9beea1574
commit
ff952aa083
2 changed files with 23 additions and 1 deletions
|
|
@ -760,6 +760,28 @@ async def predict_batch(request: BatchPredictRequest):
|
|||
detail="Pipeline configuration not loaded"
|
||||
)
|
||||
|
||||
# Validate date range
|
||||
try:
|
||||
start_dt = datetime.strptime(request.start_date, "%Y-%m-%d")
|
||||
end_dt = datetime.strptime(request.end_date, "%Y-%m-%d")
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Invalid date format. Use YYYY-MM-DD",
|
||||
)
|
||||
|
||||
if end_dt < start_dt:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="end_date must be after start_date",
|
||||
)
|
||||
|
||||
if (end_dt - start_dt).days > 365:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Date range cannot exceed 1 year",
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Batch predict: {request.pair} {request.timeframe} "
|
||||
f"from {request.start_date} to {request.end_date}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue