Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/strands_compose_chat/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
"""Admin panel: sqladmin views and authentication backend."""
"""Admin panel: sqladmin views and authentication backend.

Importing this package applies the sqladmin/wtforms compatibility shim (see
``compat``) so boolean form fields render under wtforms 3.2 before any admin
view is constructed.
"""

from .compat import apply_wtforms_compat

apply_wtforms_compat()
27 changes: 27 additions & 0 deletions src/strands_compose_chat/admin/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Compatibility shim for sqladmin widgets against supported wtforms versions.

sqladmin's ``BooleanInputWidget`` subclasses wtforms' base ``Input`` widget
without declaring ``validation_attrs``. wtforms 3.1 defined that attribute on the
base ``Input`` class, so the widget inherited it; wtforms 3.2 moved
``validation_attrs`` onto each concrete widget subclass, leaving
``BooleanInputWidget`` without it. Rendering any boolean form field then raises
``AttributeError`` inside ``Input.__call__``.

This shim gives the widget the checkbox validation attributes it should have had,
restoring boolean-field rendering under wtforms 3.2 without waiting on an sqladmin
release. It is a no-op on wtforms 3.1, where the attribute is already inherited.
"""

from sqladmin.widgets import BooleanInputWidget
from wtforms.widgets import CheckboxInput


def apply_wtforms_compat() -> None:
"""Ensure sqladmin's ``BooleanInputWidget`` declares ``validation_attrs``.

Idempotent: only assigns when the attribute is missing, so it is safe to call
once during app construction and does nothing on wtforms versions that already
provide it via the base ``Input`` widget.
"""
if not hasattr(BooleanInputWidget, "validation_attrs"):
setattr(BooleanInputWidget, "validation_attrs", list(CheckboxInput.validation_attrs))
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.