[Python] How to create list of UUID field

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    I need to create a list of UUID field:

    from uuid import UUID
    from sqlalchemy import UUID as saUUID


    class Subsection(LastActionModelMixin, Base):
    __tablename__ = "help_subsection"

    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    document_ids: Mapped[list[UUID]] = mapped_column(ARRAY(saUUID), default_factory=list)


    The code above produces exception:


    sqlalchemy.exc.ArgumentError: Attribute 'document_ids' on class <class'app.models.help.Subsection'> includes dataclasses argument(s): 'default_factory' but class does not specify SQLAlchemy native dataclass configuration.
    ​

    How to fix the error?

    Continue reading...

Compartilhe esta Página