-
Notifications
You must be signed in to change notification settings - Fork 270
Description
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
sqladmin 0.22.0 throws TypeError: issubclass() arg 1 must be a class when accessing the detail view for models with UUID primary keys using Annotated types. This is a regression introduced in version 0.22.0 - version 0.21.0 works correctly.
Steps to reproduce the bug
- Create a model with UUID primary key using Annotated:
from uuid import UUID
from typing import Annotated
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "users"
id: Mapped[UUID] = mapped_column(primary_key=True)- Set up sqladmin with this model
- Navigate to user list view (works fine)
- Click to view user details:
/admin/user/details/{uuid} - Error occurs
Expected behavior
Detail view should load successfully, displaying the user record details as it did in sqladmin 0.21.0.
Actual behavior
Application crashes with TypeError: issubclass() arg 1 must be a class when trying to access any detail view for models with UUID primary keys.
Debugging material
Full Traceback
``` File ".../sqladmin/models.py", line 904, in get_object_for_details stmt = self.details_query(request) File ".../sqladmin/models.py", line 1162, in details_query return self.form_edit_query(request) File ".../sqladmin/models.py", line 1178, in form_edit_query stmt = self._stmt_by_identifier(request.path_params["pk"]) File ".../sqladmin/models.py", line 918, in _stmt_by_identifier values = object_identifier_values(identifier, self.model) File ".../sqladmin/helpers.py", line 230, in object_identifier_values if issubclass(type_, (date, datetime, time)): ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: issubclass() arg 1 must be a class ```Root Cause:
PR #958 added a date/time type check in helpers.py:230 but doesn't handle Annotated types properly. When type_ is a typing._AnnotatedAlias (not an actual class), issubclass() fails.
Proposed Fix:
# sqladmin/helpers.py line ~230
if isinstance(type_, type) and issubclass(type_, (date, datetime, time)):
# existing logicEnvironment
- sqladmin: 0.22.0
- Python: 3.13
- SQLAlchemy: 2.0.38
- pydantic: 2.10.6
Additional context
This regression was introduced in PR #958 which aimed to fix date/time primary key handling. The fix works for date/time types but breaks UUID primary keys when using type annotations.
Workaround: Downgrade to sqladmin 0.21.0