โ† baseline_full_v2

fastapi_14512

failed NO_PATCH NO_PATCH UNSUBMITTED empty_patch(None) ยท None tool calls ยท 0 s ยท fastapi/fastapi

Task input

๐Ÿ› Fix support for tagged union with discriminator inside of `Annotated` with `Body()`

๐Ÿ› Fix support for tagged union with discriminator inside of `Annotated` with `Body()`

Related to: https://github.com/fastapi/fastapi/discussions/14495, https://github.com/fastapi/fastapi/issues/14508

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Test output

show
ing/.envs/fastapi/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:2425: in new_handler
    schema = get_inner_schema(source)
             ^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/pydantic/_internal/_schema_generation_shared.py:83: in __call__
    schema = self._handler(source_type)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:2423: in new_handler
    schema = annotation_get_schema(source, get_inner_schema)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/pydantic/types.py:3073: in __get_pydantic_core_schema__
    return self._convert_schema(original_schema, handler)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = Discriminator(discriminator=<function client_fixture.<locals>.get_pet_type at 0x109f5ce00>, custom_error_type=None, custom_error_message=None, custom_error_context=None)
original_schema = {'type': 'union', 'choices': [{'type': 'tagged-union', 'choices': {'cat': {'type': 'definition-ref', 'schema_ref': 'te...c_internal_union_tag_key': 'dog'}}}, 'discriminator': <function client_fixture.<locals>.get_pet_type at 0x109f5ce00>}]}
handler = <pydantic._internal._schema_generation_shared.CallbackGetCoreSchemaHandler object at 0x10a17c830>

    def _convert_schema(
        self, original_schema: core_schema.CoreSchema, handler: GetCoreSchemaHandler | None = None
    ) -> core_schema.TaggedUnionSchema:
        if handler is not None and original_schema['type'] == 'definition-ref':
            # Same logic as `_ApplyInferredDiscriminator._apply_to_root()`
            try:
                def_schema = handler.resolve_ref_schema(original_schema)
            except LookupError:  # pragma: no cover
                from pydantic._internal._discriminated_union import MissingDefinitionForUnionRef
    
                raise MissingDefinitionForUnionRef(original_schema['schema_ref'])
    
            # If using a referenceable union as discriminated (e.g. `type Pet = Cat | Dog; field: Pet = Field(discriminator=...)`):
            if def_schema['type'] == 'union':
                original_schema = def_schema.copy()
                original_schema.pop('ref')
    
        if original_schema['type'] != 'union':
            # This likely indicates that the schema was a single-item union that was simplified.
            # In this case, we do the same thing we do in
            # `pydantic._internal._discriminated_union._ApplyInferredDiscriminator._apply_to_root`, namely,
            # package the generated schema back into a single-item union.
            original_schema = core_schema.union_schema([original_schema])
    
        tagged_union_choices = {}
        for choice in original_schema['choices']:
            tag = None
            if isinstance(choice, tuple):
                choice, tag = choice
            metadata = cast('CoreMetadata | None', choice.get('metadata'))
            if metadata is not None:
                tag = metadata.get('pydantic_internal_union_tag_key') or tag
            if tag is None:
                # `handler` is None when this method is called from `apply_discriminator()` (deferred discriminators)
                if handler is not None and choice['type'] == 'definition-ref':
                    # If choice was built from a PEP 695 type alias, try to resolve the def:
                    try:
                        choice = handler.resolve_ref_schema(choice)
                    except LookupError:
                        pass
                    else:
                        metadata = cast('CoreMetadata | None', choice.get('metadata'))
                        if metadata is not None:
                            tag = metadata.get('pydantic_internal_union_tag_key')
    
                if tag is None:
>                   raise PydanticUserError(
                        f'`Tag` not provided for choice {choice} used with `Discriminator`',
                        code='callable-discriminator-no-tag',
                    )
E                   pydantic.errors.PydanticUserError: `Tag` not provided for choice {'type': 'tagged-union', 'choices': {'cat': {'type': 'definition-ref', 'schema_ref': 'tests.test_union_body_discriminator_annotated.client_fixture.<locals>.Cat:4417505696', 'metadata': {'pydantic_internal_union_tag_key': 'cat'}}, 'dog': {'type': 'definition-ref', 'schema_ref': 'tests.test_union_body_discriminator_annotated.client_fixture.<locals>.Dog:4462914160', 'metadata': {'pydantic_internal_union_tag_key': 'dog'}}}, 'discriminator': <function client_fixture.<locals>.get_pet_type at 0x109f5ce00>} used with `Discriminator`
E                   
E                   For further information visit https://errors.pydantic.dev/2.13/u/callable-discriminator-no-tag

/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/pydantic/types.py:3121: PydanticUserError
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45
  /Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.50.0-py3-none-any/starlette/testclient.py:45: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
    _PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 warning, 1 error in 0.79s