I've gotten around the issue for now like so: Base = automap_base()
def iter_object(obj): return ((c.key, getattr(obj, c.key)) for c in inspect(obj).mapper.column_attrs) class MediacloudStory(Base): __tablename__ = 'mediacloud_stories' def __iter__(self): return iter_object(self) engine = create_engine(DATABASE_URL) Base.prepare(engine, reflect=True) session = Session(engine) for mc_story in session.query(MediacloudStory).all(): print(dict(mc_story)) On Tuesday, March 28, 2017 at 2:06:22 AM UTC-4, Al Johri wrote: > > Hi, > > > I'm using sqlalchemy.ext.automap like so: > > > engine = create_engine(DATABASE_URL) > > Base = automap_base() > > Base.prepare(engine, reflect=True) > > MediacloudStory = Base.classes.mediacloud_stories > > > session = Session(engine) > > for mc_story in session.query(MediacloudStory).all(): > > print(mc_story) > > > I expect to be able to run dict(mc_story) to get the result as a dictionary > but I am unable to do so. I get this error: > > > TypeError: 'mediacloud_stories' object is not iterable > > > I am able to convert it to a dictionary using inspection though. > > > from sqlalchemy import inspect def object_as_dict(obj): return {c.key: > getattr(obj, c.key) for c in inspect(obj).mapper.column_attrs} > > The function above works fine. > > > It seems like dict(myobj) should be supported. > > > Thanks, > > Al > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.