convert sqlalchemy query result to a list of dicts

Try

result_dict = [u.__dict__ for u in my_query.all()]

Besides what is the type of your result_dict before the for loop? Its behavior is rather strange.


This works now

result_dict = [u._asdict() for u in my_query.all()]

The reason is that u is not actually a tuple but a KeyedTuple.

The correct answer on this thread also would be helpful


There's no .all()

You can try:

result_dict = [u.__dict__ for u in my_query.fetchall()]