6

How can I convert a sqlalchemy.engine.result.RowProxy to a dictionary?

row = db.engine.execute(sql, id=id).fetchone()

Tried using this from SO question:

for c in inspect(obj).mapper.column_attrs:
    model_col = getattr(obj, c.key)
    model_dict[c.key] = model_col

Error:

sqlalchemy.exc.NoInspectionAvailable: No inspection system is available for object of type <class 'sqlalchemy.engine.result.RowProxy'>
Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
el_pup_le
  • 11,711
  • 26
  • 85
  • 142
  • You're looking at the wrong answer (of the many). Use https://stackoverflow.com/a/1958228/2681632. The answer you tried is for entities, or in other words model objects. – Ilja Everilä Aug 03 '18 at 05:12
  • Also in some situations you might not even need the conversion. `RowProxy` objects are mappings on their own already. – Ilja Everilä Aug 03 '18 at 05:21

0 Answers0