|
14 | 14 | WithJsonSchema, |
15 | 15 | create_model, |
16 | 16 | ) |
| 17 | +from pydantic.errors import PydanticSchemaGenerationError |
17 | 18 | from pydantic.fields import FieldInfo |
18 | 19 | from pydantic.json_schema import GenerateJsonSchema, JsonSchemaWarningKind |
19 | 20 | from typing_extensions import is_typeddict |
@@ -364,7 +365,7 @@ def _try_create_model_and_schema( |
364 | 365 | if len(args) == 2 and args[0] is str: |
365 | 366 | # TODO: should we use the original annotation? We are loosing any potential `Annotated` |
366 | 367 | # metadata for Pydantic here: |
367 | | - model = _create_dict_model(func_name, type_expr) |
| 368 | + model = _create_dict_model(func_name, original_annotation) |
368 | 369 | else: |
369 | 370 | # dict with non-str keys needs wrapping |
370 | 371 | model = _create_wrapped_model(func_name, original_annotation) |
@@ -411,12 +412,19 @@ def _try_create_model_and_schema( |
411 | 412 | # Use StrictJsonSchema to raise exceptions instead of warnings |
412 | 413 | try: |
413 | 414 | schema = model.model_json_schema(schema_generator=StrictJsonSchema) |
414 | | - except (TypeError, ValueError, pydantic_core.SchemaError, pydantic_core.ValidationError) as e: |
| 415 | + except ( |
| 416 | + TypeError, |
| 417 | + ValueError, |
| 418 | + pydantic_core.SchemaError, |
| 419 | + pydantic_core.ValidationError, |
| 420 | + PydanticSchemaGenerationError, |
| 421 | + ) as e: |
415 | 422 | # These are expected errors when a type can't be converted to a Pydantic schema |
416 | 423 | # TypeError: When Pydantic can't handle the type |
417 | 424 | # ValueError: When there are issues with the type definition (including our custom warnings) |
418 | 425 | # SchemaError: When Pydantic can't build a schema |
419 | 426 | # ValidationError: When validation fails |
| 427 | + # PydanticSchemaGenerationError: When pydantic-core cannot generate a schema for a type |
420 | 428 | logger.info(f"Cannot create schema for type {type_expr} in {func_name}: {type(e).__name__}: {e}") |
421 | 429 | return None, None, False |
422 | 430 |
|
|
0 commit comments