I want the result of my query to be converted to a dicts list as follows:
result_dict = [{'category': 'failure', 'week': '1209', 'stat': 'tdc_ok', 'severityDue': '2_critic'}, {'category': 'failure', 'week': '1210', 'stat': 'tdc_nok', 'severityDue': '2_critic'}]
But instead, I get it as a dict, this way with duplicate keys:
result_dict = {'category': 'failure', 'week': '1209', 'stat': 'tdc_ok', 'severityDue': '2_critic', 'category': 'failure', 'week': '1210', 'stat': 'tdc_nok', 'severityDue': '2_critic'}
I get this result by doing this:
for u in my_query.all(): result_dict = u.__dict__
How to convert sqlAlchemy query result to dicts list (each row will be dict)?
help me please
source share