Closed peterdudfield closed 22 hours ago
Hi, I would take this issue. Question is: Do you want to limit the number of entries in the class, such as
class MultiplePVActual(BaseModel):
"""Site data for one site"""
site_uuid: str = Field(..., json_schema_extra={"description": "The site id"})
pv_actual_values: List[PVActualValue] = Field(
..., json_schema_extra={"description": "List of datetimes and generation"}
)
# Limiting list lenght to 1000 entires
@field_validator("pv_actual_values")
def check_number_of_entries(cls, v):
if len(v) > 1000:
raise ValueError("The list must contain no more than 1000 entries.")
return v
which would return a 422 Error in the response
alternatively restricting the content_lenght in the route directly
content_length = int(request.headers.get("Content-Length", 0))
max_payload_size = 1024 * 1024 # equalse to 1 MB
if content_length > max_payload_size:
raise HTTPException(status_code=413, detail="Payload too large")
or I could just check the length of the pv_actual_values
and raise 413
Looks amazing. I'm easy which one we use. Maybe put the 1 mb one in?
Detailed Description
is there a way to restrict the amount of data being posted.
Context
Possible Implementation