Clear sqlalchemy reflection cache

Posted by OrganicPanda on Stack Overflow See other posts from Stack Overflow or by OrganicPanda
Published on 2010-06-18T09:10:30Z Indexed on 2010/06/18 9:13 UTC
Read the original article Hit count: 197

Filed under:
|

Hi all,

I'm using sqlalchemy's reflection tools to get a Table object. I do this because these tables are dynamic and tables/columns can change. Here's the code I'm using:

def getTableByReflection(self, tableName, metadata, engine):

    return Table(tableName, metadata, autoload = True, autoload_with = engine)

The problem is that when the above code is run twice it seems to return the same results regardless of whether or not the columns have changed. I have tried refreshing using the mysession.refresh(mytable) but that fails because the table is not attached to any metadata - which makes sense but then why am I seeing cached results?

Is there any way to tell the metadata/engine/session to forget about this table and let me load it cleanly?

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy