On 08/11/2016 01:24 PM, Demitri Muna wrote:
Hi Mike,

It looks like my Base class was not exactly the same (although it was in
my original code), but this is not the problem.

I didn't think it was, but it's very difficult for me to be helpful when I only get various out of context lines of code here. I can only suggest that you look in the SQL logs and use pdb to figure out where the state is getting lost.


I have a custom
"DatabaseConnection" Python class that is a singleton and encapsulates
the database connection. It's constructed like this:

me.engine = create_engine(me.database_connection_string, echo=False)
me.metadata = MetaData()
me.metadata.bind = me.engine
me.Base = declarative_base(bind=me.engine)
me.Session = scoped_session(sessionmaker(bind=me.engine, autocommit=True))

"me" refers to the cls (i.e. "self"). When I later call
DatabaseConnection (my variable dbc, the singleton), I access the
metadata, Base, and Session from it. You pointed out that my metadata
was not the same instance.

I found if I later call "dbc.Base", the metadata is empty, whereas if
later I use the singleton and call:

Base = declarative_base(bind=dbc.engine)

this works. (In fact, this has been my pattern for years.) I don't know
why the Base defined as above remains empty while a later call to
"declarative_base" from another file works, but it's not crucial.

To your original question, this is what I get back from the metadata.

ipdb> Base.metadata.tables.keys()
dict_keys(['file.fits_header_keyword', 'file.fits_header_comment',
'trillian.dataset', 'file.fits_hdu', 'file.fits_header_value',
'trillian.dataset_release', 'file.file_kind', 'file.fits_file',
'file.base_path'])

so...those are the right names right? it should be working. I can't do much else on this end unless you could produce a self-contained demonstration case.






Thanks,
Demitri

--
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
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
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.

Reply via email to