mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-13 04:59:04 +08:00
fix(http_request): handle empty and string data inputs (#9579)
This commit is contained in:
parent
740a723072
commit
38a4f0234d
@ -1,5 +1,5 @@
|
||||
from collections.abc import Sequence
|
||||
from typing import Literal, Optional
|
||||
from typing import Any, Literal, Optional
|
||||
|
||||
import httpx
|
||||
from pydantic import BaseModel, Field, ValidationInfo, field_validator
|
||||
@ -52,6 +52,16 @@ class HttpRequestNodeBody(BaseModel):
|
||||
type: Literal["none", "form-data", "x-www-form-urlencoded", "raw-text", "json", "binary"]
|
||||
data: Sequence[BodyData] = Field(default_factory=list)
|
||||
|
||||
@field_validator("data", mode="before")
|
||||
@classmethod
|
||||
def check_data(cls, v: Any):
|
||||
"""For compatibility, if body is not set, return empty list."""
|
||||
if not v:
|
||||
return []
|
||||
if isinstance(v, str):
|
||||
return [BodyData(key="", type="text", value=v)]
|
||||
return v
|
||||
|
||||
|
||||
class HttpRequestNodeTimeout(BaseModel):
|
||||
connect: int = dify_config.HTTP_REQUEST_MAX_CONNECT_TIMEOUT
|
||||
|
Loading…
x
Reference in New Issue
Block a user