|
|
@ -15,6 +15,7 @@ from collections.abc import ( |
|
|
from contextlib import AsyncExitStack, contextmanager |
|
|
from contextlib import AsyncExitStack, contextmanager |
|
|
from copy import copy, deepcopy |
|
|
from copy import copy, deepcopy |
|
|
from dataclasses import dataclass |
|
|
from dataclasses import dataclass |
|
|
|
|
|
from functools import lru_cache |
|
|
from typing import ( |
|
|
from typing import ( |
|
|
Annotated, |
|
|
Annotated, |
|
|
Any, |
|
|
Any, |
|
|
@ -64,11 +65,10 @@ from fastapi.utils import ( |
|
|
create_model_field, |
|
|
create_model_field, |
|
|
get_path_param_names, |
|
|
get_path_param_names, |
|
|
) |
|
|
) |
|
|
from pydantic import BaseModel, Json, TypeAdapter, create_model, ValidationError |
|
|
from pydantic import BaseModel, Json, TypeAdapter, ValidationError, create_model |
|
|
from pydantic.fields import FieldInfo |
|
|
from pydantic.fields import FieldInfo |
|
|
from starlette.background import BackgroundTasks as StarletteBackgroundTasks |
|
|
from starlette.background import BackgroundTasks as StarletteBackgroundTasks |
|
|
from starlette.concurrency import run_in_threadpool |
|
|
from starlette.concurrency import run_in_threadpool |
|
|
from functools import lru_cache |
|
|
|
|
|
from starlette.datastructures import ( |
|
|
from starlette.datastructures import ( |
|
|
FormData, |
|
|
FormData, |
|
|
Headers, |
|
|
Headers, |
|
|
@ -760,9 +760,12 @@ def _validate_value_with_model_field( |
|
|
|
|
|
|
|
|
# If it's a scalar and we have bytes, we MUST decode it first because Pydantic's |
|
|
# If it's a scalar and we have bytes, we MUST decode it first because Pydantic's |
|
|
# validate_python doesn't handle JSON-encoded scalar bytes (like b'"-1"') |
|
|
# validate_python doesn't handle JSON-encoded scalar bytes (like b'"-1"') |
|
|
if isinstance(value, bytes) and field_annotation_is_scalar(field.field_info.annotation): |
|
|
if isinstance(value, bytes) and field_annotation_is_scalar( |
|
|
|
|
|
field.field_info.annotation |
|
|
|
|
|
): |
|
|
try: |
|
|
try: |
|
|
import json |
|
|
import json |
|
|
|
|
|
|
|
|
value = json.loads(value) |
|
|
value = json.loads(value) |
|
|
except json.JSONDecodeError: |
|
|
except json.JSONDecodeError: |
|
|
pass |
|
|
pass |
|
|
@ -1051,6 +1054,7 @@ async def request_body_to_args( |
|
|
if isinstance(received_body, bytes): |
|
|
if isinstance(received_body, bytes): |
|
|
try: |
|
|
try: |
|
|
import json |
|
|
import json |
|
|
|
|
|
|
|
|
body_to_process = json.loads(received_body) |
|
|
body_to_process = json.loads(received_body) |
|
|
except json.JSONDecodeError as e: |
|
|
except json.JSONDecodeError as e: |
|
|
return values, [ |
|
|
return values, [ |
|
|
|