update to make work with latest master changes

Signed-off-by: merlinz01 <158784988+merlinz01@users.noreply.github.com>
This commit is contained in:
merlinz01 2024-10-12 21:59:00 -04:00
parent 6d9130a02a
commit 6e3c519002
3 changed files with 15 additions and 16 deletions

View File

@ -23,6 +23,7 @@ from .v2 import ModelField as ModelField
from .v2 import PydanticSchemaGenerationError as PydanticSchemaGenerationError
from .v2 import RequiredParam as RequiredParam
from .v2 import Undefined as Undefined
from .v2 import UndefinedType as UndefinedType
from .v2 import Url as Url
from .v2 import copy_field_info as copy_field_info
from .v2 import create_body_model as create_body_model

View File

@ -27,7 +27,7 @@ from pydantic.fields import FieldInfo as FieldInfo
from pydantic.json_schema import GenerateJsonSchema as GenerateJsonSchema
from pydantic.json_schema import JsonSchemaValue as JsonSchemaValue
from pydantic_core import CoreSchema as CoreSchema
from pydantic_core import PydanticUndefined
from pydantic_core import PydanticUndefined, PydanticUndefinedType
from pydantic_core import Url as Url
from pydantic_core.core_schema import (
with_info_plain_validator_function as with_info_plain_validator_function,
@ -36,6 +36,7 @@ from typing_extensions import Literal, get_args, get_origin
RequiredParam = PydanticUndefined
Undefined = PydanticUndefined
UndefinedType = PydanticUndefinedType
evaluate_forwardref = eval_type_lenient
# TODO: remove when dropping support for Pydantic < v2.12.3

View File

@ -708,30 +708,26 @@ async def solve_dependencies(
)
if PYDANTIC_V2:
if sys.hexversion >= 0x30A0000:
if sys.hexversion >= 0x030A0000 and sys.hexversion < 0x030E0000:
def _allows_none(field: ModelField) -> bool:
origin = get_origin(field.type_)
return (origin is Union or origin is types.UnionType) and type(
None
) in get_args(field.type_)
else:
def _allows_none(field: ModelField) -> bool:
origin = get_origin(field.field_info.annotation)
return (origin is Union or origin is types.UnionType) and type(
None
) in get_args(field.field_info.annotation)
def _allows_none(field: ModelField) -> bool:
origin = get_origin(field.type_)
return origin is Union and type(None) in get_args(field.type_)
else:
def _allows_none(field: ModelField) -> bool:
return field.allow_none # type: ignore
origin = get_origin(field.field_info.annotation)
return origin is Union and type(None) in get_args(field.field_info.annotation)
def _validate_value_with_model_field(
*, field: ModelField, value: Any, values: dict[str, Any], loc: tuple[str, ...]
) -> tuple[Any, list[Any]]:
if value is Undefined:
if field.required:
if field.field_info.is_required():
return None, [get_missing_field_error(loc=loc)]
else:
return deepcopy(field.default), []
@ -753,6 +749,7 @@ def _get_multidict_value(
field: ModelField, values: Mapping[str, Any], alias: Union[str, None] = None
) -> Any:
alias = alias or get_validation_alias(field)
value: Any
if (
(not _is_json_field(field))
and field_annotation_is_sequence(field.field_info.annotation)
@ -822,7 +819,7 @@ def request_params_to_args(
if alias == field.name:
alias = alias.replace("_", "-")
value = _get_multidict_value(field, received_params, alias=alias)
if value is not None:
if value is not Undefined and value is not None:
params_to_process[get_validation_alias(field)] = value
processed_keys.add(alias or get_validation_alias(field))
@ -987,7 +984,7 @@ async def request_body_to_args(
return {first_field.name: v_}, errors_
for field in body_fields:
loc = ("body", get_validation_alias(field))
value: Optional[Any] = Undefined
value: Any = Undefined
if body_to_process is not None and not isinstance(
body_to_process, UndefinedType
):