Skip to content

[Bug]: SQLAlchemy MappedAnnotationError in autoapi v3 mixins - incompatible type annotations with SQLAlchemy 2.0+ #3499

@MichaelDecent

Description

@MichaelDecent

Describe the Bug

The autoapi v3 mixins are using legacy type annotations that are incompatible with SQLAlchemy 2.0+, causing MappedAnnotationError when models inherit from mixins like GUIDPk and Timestamped

Steps to Reproduce

  1. Create a model that inherits from autoapi v3 mixins:
from autoapi.v3.mixins import GUIDPk, Timestamped
from autoapi.v3.tables import Base

class MyModel(Base, GUIDPk, Timestamped):
    __tablename__ = "my_models"
    # ... other fields
  1. Try to import or use the model
  2. SQLAlchemy will raise MappedAnnotationError

Software Version

<0.4.0

Python Version

Python 3.8

Environment Details

SQLAlchemy: 2.0+
Python: 3.12
autoapi: v3

Relevant Logs or Error Output

File "auto_kms/tables/key_version.py", line 29, in <module>
  class KeyVersion(Base, GUIDPk, Timestamped):
File "autoapi/v3/tables/_base.py", line 172, in __init_subclass__
  super().__init_subclass__(**kw)
File "sqlalchemy/orm/decl_api.py", line 842, in __init_subclass__
  _as_declarative(cls._sa_registry, cls, cls.__dict__)
[...traceback continues...]
sqlalchemy.orm.exc.MappedAnnotationError: Type annotation for "KeyVersion.id" can't be correctly interpreted...

Additional Context (Optional)

No response

Confirmation

  • I have searched the existing issues for this bug.
  • I have provided all necessary information to reproduce the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions