fix: Add the missing validation of doc_form in the service API. (#32892)

This commit is contained in:
FFXN
2026-03-03 15:54:43 +08:00
committed by GitHub
parent c8688ec371
commit 2068640a4b
4 changed files with 47 additions and 2 deletions

View File

@ -4,7 +4,7 @@ from uuid import UUID
from flask import request
from flask_restx import marshal
from pydantic import BaseModel, Field, model_validator
from pydantic import BaseModel, Field, field_validator, model_validator
from sqlalchemy import desc, select
from werkzeug.exceptions import Forbidden, NotFound
@ -60,6 +60,13 @@ class DocumentTextCreatePayload(BaseModel):
embedding_model: str | None = None
embedding_model_provider: str | None = None
@field_validator("doc_form")
@classmethod
def validate_doc_form(cls, value: str) -> str:
if value not in Dataset.DOC_FORM_LIST:
raise ValueError("Invalid doc_form.")
return value
DEFAULT_REF_TEMPLATE_SWAGGER_2_0 = "#/definitions/{model}"
@ -72,6 +79,13 @@ class DocumentTextUpdate(BaseModel):
doc_language: str = "English"
retrieval_model: RetrievalModel | None = None
@field_validator("doc_form")
@classmethod
def validate_doc_form(cls, value: str) -> str:
if value not in Dataset.DOC_FORM_LIST:
raise ValueError("Invalid doc_form.")
return value
@model_validator(mode="after")
def check_text_and_name(self) -> Self:
if self.text is not None and self.name is None: