[Python] SQLAlchemy session.query(object) returns automap object without __dict__ [duplicate]

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    I follow up this tutorial and got an error.

    Code:

    engine = create_engine("sqlite:///mydatabase.db")

    # reflect the tables
    Base.prepare(autoload_with=engine)

    # mapped classes are now created with names by default
    # matching that of the table name.
    User = Base.classes.user
    u1 = session.query(User).first()
    print(u1.id)


    Error:

    {AttributeError}AttributeError('id')


    __dict__ also doesn't work. I've got an object of (<sqlalchemy.ext.automap.user object at 0x78d606a35010>,) class.

    How to obtain the properties of the object returned by a select/query statements?

    Continue reading...

Compartilhe esta Página