Skip to content

Exception when column is of type Annotated #1013

@vsemionov

Description

@vsemionov

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

When viewing details of objects with columns of type Annotated, the following exception is raised here:

TypeError: issubclass() arg 1 must be a class

One case when this happens is with user objects of FastAPI Users. Here's how this library defines its user class:

id: Mapped[UUID_ID] = mapped_column(GUID, primary_key=True, default=uuid.uuid4)

Where UUID_ID is just uuid.UUID, and GUID is defined here.

My local workaround is to wrap get_column_python_type, and if the returned type is Annotated, return the actual wrapped type:

def _patched_get_column_python_type(column: Column) -> type:
    type_ = get_column_python_type(column)
    if get_origin(type_) is Annotated:
        type_ = get_args(type_)[0]
    return type_

Steps to reproduce the bug

No response

Expected behavior

No response

Actual behavior

No response

Debugging material

No response

Environment

  • MacOS, Python 3.13, SQLAdmin 0.23.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions