coaster
coaster copied to clipboard
StateManager query interface may need to change
StateManager currently allows database queries like this:
Document.query.filter(Document.state.PUBLISHED).all()
Unfortunately, this makes it impossible to examine the PUBLISHED
workflow state, as any attempt to access it will render a query. The rendering could shift to a function call:
Document.query.filter(Document.state.PUBLISHED()).all()
This is a breaking change unless SQLAlchemy provides us a way to cast an object into a SQL expression.
This change mirrors the changes introduced in #166 (specifically, 8979fa97ba0cd3f50d03e647d73ad456a1dfd11f, for #165), where instead of returning a boolean when accessed via the instance, we return an object that implements __bool__
. Unfortunately, SQLAlchemy doesn't give us an equivalent __sql__
, and inheriting from ClauseElement
will have unknown side effects.
To be investigated: will it work to offer a __clause_element__
method? This appears to be what SQLAlchemy calls.