re-implement PrivateColumn to make sqlalchemy happy

This commit is contained in:
Michael Genson
2026-05-14 19:13:45 +00:00
parent 37fd0c8510
commit b2497295c3

View File

@@ -14,11 +14,15 @@ from ._model_utils.datetime import NaiveDateTime, get_utc_now
NORMALIZE_PUNCTUATION = string.punctuation.replace("'", "").replace('"', "")
_NORMALIZE_PUNCTUATION_TABLE = str.maketrans(NORMALIZE_PUNCTUATION, " " * len(NORMALIZE_PUNCTUATION))
type PrivateColumn[T] = Mapped[Annotated[T, mapped_column(info={"private": True})]]
"""
A `Mapped` attribute with metadata `private=True`.
Signals to the query filter API not to allow using this field in query operations.
"""
class PrivateColumn[T]:
"""
Drop-in replacement for `Mapped[]` that marks a column as private.
Private columns cannot be used in query filter expressions.
"""
def __class_getitem__(cls, item: type) -> type:
return Mapped[Annotated[item, mapped_column(info={"private": True})]]
class SqlAlchemyBase(DeclarativeBase):