Browse Source

Merge 7d6599b027 into 1d434dec47

pull/11853/merge
Mathieu Bressolle-Chataigner 4 days ago
committed by GitHub
parent
commit
1a841fdf48
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      fastapi/_compat.py
  2. 3
      fastapi/utils.py

6
fastapi/_compat.py

@ -56,6 +56,9 @@ if PYDANTIC_V2:
) )
from pydantic._internal._typing_extra import eval_type_lenient from pydantic._internal._typing_extra import eval_type_lenient
from pydantic._internal._utils import lenient_issubclass as lenient_issubclass from pydantic._internal._utils import lenient_issubclass as lenient_issubclass
from pydantic.errors import (
PydanticUndefinedAnnotation as PydanticUndefinedAnnotation,
)
from pydantic.fields import FieldInfo from pydantic.fields import FieldInfo
from pydantic.json_schema import GenerateJsonSchema as GenerateJsonSchema from pydantic.json_schema import GenerateJsonSchema as GenerateJsonSchema
from pydantic.json_schema import JsonSchemaValue as JsonSchemaValue from pydantic.json_schema import JsonSchemaValue as JsonSchemaValue
@ -367,6 +370,9 @@ else:
class PydanticSchemaGenerationError(Exception): # type: ignore[no-redef] class PydanticSchemaGenerationError(Exception): # type: ignore[no-redef]
pass pass
class PydanticUndefinedAnnotation(Exception): # type: ignore[no-redef]
pass
def with_info_plain_validator_function( # type: ignore[misc] def with_info_plain_validator_function( # type: ignore[misc]
function: Callable[..., Any], function: Callable[..., Any],
*, *,

3
fastapi/utils.py

@ -20,6 +20,7 @@ from fastapi._compat import (
BaseConfig, BaseConfig,
ModelField, ModelField,
PydanticSchemaGenerationError, PydanticSchemaGenerationError,
PydanticUndefinedAnnotation,
Undefined, Undefined,
UndefinedType, UndefinedType,
Validator, Validator,
@ -94,7 +95,7 @@ def create_model_field(
) )
try: try:
return ModelField(**kwargs) # type: ignore[arg-type] return ModelField(**kwargs) # type: ignore[arg-type]
except (RuntimeError, PydanticSchemaGenerationError): except (RuntimeError, PydanticSchemaGenerationError, PydanticUndefinedAnnotation):
raise fastapi.exceptions.FastAPIError( raise fastapi.exceptions.FastAPIError(
"Invalid args for response field! Hint: " "Invalid args for response field! Hint: "
f"check that {type_} is a valid Pydantic field type. " f"check that {type_} is a valid Pydantic field type. "

Loading…
Cancel
Save