In this StackOverflow question one can learn how to convert the result of a query in SQLalchemy to a Python dict - which is exactly what I need. However, when I run the following code:
# TrainingSession is my DB table, derived from SQLAlchemy.db.Model
queued_session = (
TrainingSession.query.filter_by(status="queued")
.order_by(TrainingSession.training_utc_submit)
.first()
)
if queued_session:
d = dict(queued_session)
Then the last line (i.e. conversion to dict) leads to the following error:
TypeError: 'TrainingSession' object is not iterable
And if I try to call the _asdict() method then I get the error that a TrainingSession object has no such attribute. What am I doing wrong and differently from the solution in the linked answer?