Commit
·
94062ea
1
Parent(s):
5701ca8
Change budget_amount validation to auto-cap corrupted data instead of rejecting requests
Browse files- app/models.py +5 -2
app/models.py
CHANGED
|
@@ -44,15 +44,18 @@ class CategoryExpense(BaseModel):
|
|
| 44 |
class RecommendationRequest(BaseModel):
|
| 45 |
user_id: str = Field(..., description="User identifier")
|
| 46 |
category_id: str = Field(..., description="Category ID to check for previous data")
|
| 47 |
-
budget_amount: Optional[float] = Field(None, gt=0,
|
| 48 |
|
| 49 |
@validator('budget_amount')
|
| 50 |
def validate_budget_amount(cls, v):
|
| 51 |
if v is not None:
|
| 52 |
if v <= 0:
|
| 53 |
raise ValueError('budget_amount must be greater than 0')
|
|
|
|
|
|
|
| 54 |
if v > 1e12: # More than 1 trillion is likely corrupted data
|
| 55 |
-
|
|
|
|
| 56 |
return v
|
| 57 |
|
| 58 |
class RecommendationResponse(BaseModel):
|
|
|
|
| 44 |
class RecommendationRequest(BaseModel):
|
| 45 |
user_id: str = Field(..., description="User identifier")
|
| 46 |
category_id: str = Field(..., description="Category ID to check for previous data")
|
| 47 |
+
budget_amount: Optional[float] = Field(None, gt=0, description="Current budget amount for this category (optional)")
|
| 48 |
|
| 49 |
@validator('budget_amount')
|
| 50 |
def validate_budget_amount(cls, v):
|
| 51 |
if v is not None:
|
| 52 |
if v <= 0:
|
| 53 |
raise ValueError('budget_amount must be greater than 0')
|
| 54 |
+
# Auto-cap unreasonably large numbers instead of rejecting
|
| 55 |
+
# This handles corrupted data gracefully - cap at 1 trillion
|
| 56 |
if v > 1e12: # More than 1 trillion is likely corrupted data
|
| 57 |
+
print(f"⚠️ Auto-capping corrupted budget_amount: {v:,.2e} -> 1,000,000,000,000")
|
| 58 |
+
return 1e12 # Cap at 1 trillion instead of rejecting
|
| 59 |
return v
|
| 60 |
|
| 61 |
class RecommendationResponse(BaseModel):
|