On Mon, Jan 9, 2023, at 8:50 PM, mkmo...@gmail.com wrote: > Hello, > > It looks like in 2.0 we can no longer treat a row.Row as a dict. I have a few > cases where I want to do this, such as when I need to get a list of columns, > or when I don't know the column name in advance. > > rows = conn.execute(select(t.c.foo)).fetchall() > > rows[0].keys() # Not Allowed > > rows[0][some_unknown_column] # not allowed > > If we need to treat it as a dict, are we supposed to be calling: > > rows[0]._asdict() > > This works, but the only issue is that our IDEs flag this as accessing a > protected member of a class. Is there any alternative? > > Thanks and best regards,
you have more options here than previously on how to treat rows, as tuples or mappings, either up front or on a per-row basis. the new API has been available as of version 1.4. Relevant links include: 1. announcement of change and rationale https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#rowproxy-is-no-longer-a-proxy-is-now-called-row-and-behaves-like-an-enhanced-named-tuple 2. migration guide https://docs.sqlalchemy.org/en/14/changelog/migration_20.html#result-rows-act-like-named-tuples 3. new tutorial coverage https://docs.sqlalchemy.org/en/14/tutorial/dbapi_transactions.html#fetching-rows included is background on how to get mappings from a Row or how to get RowMapping objects from a result up front using result.mappings(). > > Matthew > > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/10721070-ecf9-4438-87dc-a9ff6c13c0dan%40googlegroups.com > > <https://groups.google.com/d/msgid/sqlalchemy/10721070-ecf9-4438-87dc-a9ff6c13c0dan%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/aeb7fb31-d5b1-4edd-b846-8cfbb435229a%40app.fastmail.com.