#3342·litestar

Bug: DTO doesn't work with Generic tuples

Author: dshumCreated Apr 8, 2024Updated Sep 29, 2026
LabelsBug :bug:Triage Required :hospital:DTOsarea/dto

Description

As per the documentation and answer in Discord, DTO can work with generic types such as dict and tuple. Expected result of the example below is

{"name":"John","pets":[{"nickname":"Dog"},{"color":"White"}]}

Currently the result is

{"name":"John","pets":[{"id":2,"nickname":"Dog"},{"id":3,"color":"White"}]}

URL to code causing the issue

No response

MCVE

python
from dataclasses import dataclass

from litestar import Litestar, get
from litestar.dto import DTOConfig, DataclassDTO


@dataclass
class Dog:
    id: int
    nickname: str


@dataclass
class Cat:
    id: int
    color: str


@dataclass
class Person:
    id: int
    name: str
    pets: tuple[Dog, Cat]


class ReadDTO(DataclassDTO[Person]):
    config = DTOConfig(
        include={"name", "pets.0.name", "pets.1.color"}
    )


@get("/", return_dto=ReadDTO)
async def index() -> Person:
    person = Person(id=1, name="John", pets=(
        Dog(id=2, nickname="Dog"),
        Cat(id=3, color="White"),
    ))
    return person


app = Litestar(route_handlers=[index], debug=True)

Steps to reproduce

No response

Screenshots

bash
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

No response

Litestar Version

litestar[standard,pydantic]>=2.8.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)