coaster icon indicating copy to clipboard operation
coaster copied to clipboard

StateManager query interface may need to change

Open jace opened this issue 6 years ago • 2 comments

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.

jace avatar Mar 13 '18 09:03 jace

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.

jace avatar Mar 13 '18 10:03 jace

To be investigated: will it work to offer a __clause_element__ method? This appears to be what SQLAlchemy calls.

jace avatar Mar 20 '19 12:03 jace