설문조사 생성 오류
본문
설문 조사를 생성하면 {"detail":[{"type":"int_parsing","loc":["body","po_point"],"msg":"Input should be a valid integer, unable to parse string as an integer","input":""}]}
이렇게 나오네요
어디를 수정하면 될까요?
감사합니다.
답변 2
/api/v1/models/point.py
from typing import List
from pydantic import BaseModel, Field, validator, ValidationError
class PointBase(BaseModel):
po_content: str
po_point: int = Field(..., description="포인트 점수는 정수여야 합니다.")
po_rel_table: str
po_rel_id: str
po_rel_action: str
@validator("po_point", pre=True, always=True)
def validate_po_point(cls, value):
# Check if value is an integer or can be converted to an integer
if isinstance(value, str) and not value.isdigit():
raise ValueError("po_point는 정수여야 하며 빈 문자열일 수 없습니다.")
return int(value)
class PointListResponse(BaseModel):
total_points: int
page_sum_points: dict = {"positive": 0, "negative": 0}
points: List[PointBase]
po_point필드의 벡엔드는 int 정수이므로 즉 숫자가 아닌 문자열이 입력되어 전달 할려구 하니 문제가 생기는듯 합니다. 확인해보시기 바랍니다. 또는 빈값이거나 잘못된 값이 요구하는것일 수도있구요 input type="number" 을 숫자만입력 허용하도록 해보시기 바랍니다. 또는 min="0" 음수입력 방지를 해보시구요
답변을 작성하시기 전에 로그인 해주세요.