Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autodoc-typehints fails on SQLAlchemy models #405

Open
FynnFreyer opened this issue Dec 3, 2023 · 1 comment
Open

autodoc-typehints fails on SQLAlchemy models #405

FynnFreyer opened this issue Dec 3, 2023 · 1 comment

Comments

@FynnFreyer
Copy link

When trying to document a project that's using SQLAlchemy, I get the following error message:

WARNING: error while formatting signature for module.DatabaseModel.created_at: Handler <function process_signature at 0x7f3faac891c0> for event 'autodoc-process-signature' threw an exception (exception: wrapper loop when unwrapping sqlalchemy.orm.mapped_column)
WARNING: error while formatting signature for module.DatabaseModel.updated_at: Handler <function process_signature at 0x7f3faac891c0> for event 'autodoc-process-signature' threw an exception (exception: wrapper loop when unwrapping sqlalchemy.orm.mapped_column)

Extension error (sphinx_autodoc_typehints):
Handler <function process_signature at 0x7fdf8b48d1c0> for event 'autodoc-process-signature' threw an exception (exception: wrapper loop when unwrapping sqlalchemy.orm.mapped_column)

I fear SQLalchemy is generally troublesome when it comes to autodoc, which is why it's added to autodoc_mock_imports in my conf.py. Would it be possible to do something similar with sphinx-autodoc-typehints?

A reproducible example:

from datetime import datetime

from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy.sql import func


class DatabaseModel(DeclarativeBase):  # pylint: disable=too-few-public-methods
    """The declarative base for the ORM. Adds ``created_at`` and ``updated_at`` timestamp columns."""

    created_at: Mapped[datetime] = mapped_column(server_default=func.now())
    """A ``datetime`` object, that is set on creation."""

    updated_at: Mapped[datetime] = mapped_column(server_default=func.now(), server_onupdate=func.now())
    """A ``datetime`` object, that is updated on changes."""
@FynnFreyer FynnFreyer changed the title autodoc-typehints fails on SQLAlchemy types autodoc-typehints fails on SQLAlchemy models Dec 3, 2023
@gaborbernat
Copy link
Member

PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants