Skip to content

🐛 FIX: Exception when rendering CheckConstraints#19

Merged
chrisjsewell merged 3 commits intosphinx-extensions2:mainfrom
Starbat:main
Feb 26, 2024
Merged

🐛 FIX: Exception when rendering CheckConstraints#19
chrisjsewell merged 3 commits intosphinx-extensions2:mainfrom
Starbat:main

Conversation

@Starbat
Copy link
Copy Markdown
Contributor

@Starbat Starbat commented Feb 16, 2024

To get support from mypy and other tools, it is helpful to express CheckConstraints not as text but as expressions with direct reference to the column objects. This is currently not possible.

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


class Project(Schema):
    __tablename__ = "projects"

    number: Mapped[int] = mapped_column(primary_key=True)
    name: Mapped[str] = mapped_column()

    __table_args__ = (
        CheckConstraint(func.length(func.trim(name)) > 0, "check_project_has_name"),
    )

Building the docs for this model causes the following exception:

AttributeError: Neither 'BinaryExpression' object nor 'Comparator' object has an attribute 'text'

This small adjustment makes it work.

@chrisjsewell chrisjsewell changed the title FEAT: compile sqltext in CheckConstraints 🐛 FIX: Exception when rendering CheckConstraints Feb 26, 2024
Copy link
Copy Markdown
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cheers!

@chrisjsewell chrisjsewell merged commit c2927b2 into sphinx-extensions2:main Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants