diff --git a/litestar/_openapi/datastructures.py b/litestar/_openapi/datastructures.py index d6a3bdf1d6..c11ad9997d 100644 --- a/litestar/_openapi/datastructures.py +++ b/litestar/_openapi/datastructures.py @@ -1,6 +1,5 @@ from __future__ import annotations -import weakref from collections import defaultdict from typing import TYPE_CHECKING, Iterator, Sequence, _GenericAlias # type: ignore[attr-defined] @@ -97,10 +96,7 @@ def __init__(self) -> None: self._schema_key_map: dict[tuple[str, ...], RegisteredSchema] = {} self._schema_reference_map: dict[int, RegisteredSchema] = {} self._model_name_groups: defaultdict[str, list[RegisteredSchema]] = defaultdict(list) - # no need to hold onto transient FieldDefinitions here so we're using weakrefs - self._component_type_map: weakref.WeakValueDictionary[tuple[str, ...], FieldDefinition] = ( - weakref.WeakValueDictionary() - ) + self._component_type_map: dict[str, FieldDefinition] = {} def get_schema_for_field_definition(self, field: FieldDefinition) -> Schema: """Get a registered schema by its key. diff --git a/litestar/typing.py b/litestar/typing.py index 5e2fe19a1d..4eb3bbe9cc 100644 --- a/litestar/typing.py +++ b/litestar/typing.py @@ -185,7 +185,6 @@ class FieldDefinition: "raw", "safe_generic_origin", "type_wrappers", - "__weakref__", ) raw: Any diff --git a/tests/unit/test_openapi/test_schema.py b/tests/unit/test_openapi/test_schema.py index 05c77cd36d..daa57ad4c0 100644 --- a/tests/unit/test_openapi/test_schema.py +++ b/tests/unit/test_openapi/test_schema.py @@ -97,11 +97,11 @@ class Data: @post("/") def handler( data: Data, - ) -> Annotated[Data, Parameter(component_key="not_data")]: + ) -> Annotated[Data, Parameter(schema_component_key="not_data")]: return Data() @get("/") - def handler_2() -> Annotated[Data, Parameter(component_key="not_data")]: + def handler_2() -> Annotated[Data, Parameter(schema_component_key="not_data")]: return Data() app = Litestar([handler, handler_2]) @@ -142,11 +142,11 @@ class Data2: @post("/") def handler( data: Data, - ) -> Annotated[Data, Parameter(component_key="not_data")]: + ) -> Annotated[Data, Parameter(schema_component_key="not_data")]: return Data() @get("/") - def handler_2() -> Annotated[Data2, Parameter(component_key="not_data")]: + def handler_2() -> Annotated[Data2, Parameter(schema_component_key="not_data")]: return Data2() with pytest.raises(ImproperlyConfiguredException, match="Schema component keys must be unique"):