I am currently using sqlalchemy 1.4.2
I am using session.execute(statement) to fetch rows from my Db table. This is the code I have used below:
query = f"SELECT * FROM mytable WHERE entity_guid IN {entity_guids}"
results = session.execute(query)
for result in results:
print(results)
final.append({**result})
return final
The above code throws me the error:
*TypeError: tuple indices must be integers or slices, not str*
File "/opt/python/lib/python3.8/site-packages/layers/core/read_simple_entities/read_simple_entities.py", line 15, in read_entities
final.append({**result})
File "/opt/python/lib/python3.8/site-packages/sqlalchemy/engine/row.py", line 104, in __getitem__
return self._data[key]
So I updated my code to use _asdict() method:
results = session.execute(query)
for row in results:
final.append(row._asdict())
return final
But I want to know the reason its passing for some devs with the first block of code where we just unpack result dict even though i use same version of 1.4.2