Skip to content

🐛 FIX: Exception when rendering CheckConstraints #19

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

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

Starbat
Copy link
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
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