I am having an issue with multipart form data with a single array element.
Let's say the endpoint signature and deserializer look like this:
@patch(path="/l", description="qew.")
async def DP(self, request: "Request", db_session: AsyncSession, data: Annotated[DPPayload, Body(media_type=RequestEncodingType.MULTI_PART)]) -> DPPayload | Response:
...
class PetsEnum(enum.IntEnum):
DOG = 1
CAT = 2
FISH = 3
BIRD = 4
RABBIT = 5
HAMSTER = 6
GUINEA_PIG = 7
SNAKE = 8
TURTLE = 9
LIZARD = 10
OTHER = 11
class DPPayload(msgspec.Struct, kw_only=True, omit_defaults=True, repr_omit_defaults=True):
# Multiple choice fields
pets: Optional[Annotated[list[PetsEnum], msgspec.Meta(max_length=4)]] | msgspec.UnsetType = msgspec.UNSET
speaks: Optional[list[Annotated[str, msgspec.Meta(max_length=2, pattern=r'^[a-z]+$')]]] | msgspec.UnsetType = msgspec.UNSET
When I send a patch request with the following data:
pets: 3
pets: 4
It doesn't fail, and the data object at the endpoint contains a key pets with a list.
However, if I send:
pets: 2
it will be converted to dict {'pets': 2} which is completly fine and not wrong.
It (probably) fails the dependencies check in http.py at the method async def _get_response_data(...) for DPPayload.
Does anyone have an idea or solution for this?