-
The following class causes issues when generating typescript types: @dataclass
class Prefix:
path: str
is_special: bool
name: str = field(init=False)
parent: str | None = field(init=False)
children: list["Prefix"] = field(default_factory=list)
def __post_init__(self):
path = self.path.rsplit("/", maxsplit=1)
self.name = path[1] if len(path) > 1 else path[0]
self.parent = None if len(path) == 1 else path[0] I get the error
As you can see, the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
So the route that uses the above class was declared like this: @get("/list-prefixes")
async def list_prefixes(
root: Optional[str] = "", depth: int = 2, only_scans: bool = False
) -> Iterable[Prefix]:
result = list(fetch_prefixes(root, depth, only_scans))
return result Changing it to use a pagination type along with a DTO seems to have fixed the issue: class ReadPrefixesDTO(DataclassDTO[Prefix]):
config = DTOConfig(rename_strategy="camel")
@get("/list-prefixes", return_dto=ReadPrefixesDTO)
async def list_prefixes(
root: Optional[str] = "", depth: int = 2, only_scans: bool = False
) -> ClassicPagination[Prefix]:
result = list(fetch_prefixes(root, depth, only_scans))
return ClassicPagination(
items=result, page_size=len(result), current_page=1, total_pages=1
) I'm not sure I understand why this works, so any insight would be useful |
Beta Was this translation helpful? Give feedback.
-
Hey! This might be a bug. The schema generation for recursive types was added in #2869 so it should be working without needing a DTO. Could you show the full stacktrace?? |
Beta Was this translation helpful? Give feedback.
So the route that uses the above class was declared like this:
Changing it to use a pagination type along with a DTO seems to have fixed the issue: