On Tuesday 23 September 2008 11:40:16 Kirk Strauser wrote:

> How can this possibly work?  Although the Types module connects to our
> database, that session object is coming from TurboGears - and I am 100%
> sure that TG is configured to use a SQLite database.

It looks like SQLAlchemy is caching the information, and behavior depends on 
which order things are imported.  For example, given alchtest.py:

========
#!/usr/bin/env python

import sqlalchemy
from sqlalchemy import orm

dbh = sqlalchemy.create_engine('postgres://[url]')
metadata = sqlalchemy.MetaData(dbh)
session = sqlalchemy.orm.create_session()

class Package(object): pass

package_table = sqlalchemy.Table(
    'package',
    metadata,
    autoload=True,
    schema='public')

orm.mapper(Package, package_table)

def foo(sess):
    print sess.query(Package).first()
========

Now, if I import turbogears.database.session before alchtest, I get the 
behavior I would have expected:

>>> import alchtest
>>> from turbogears.database import session
>>> alchtest.foo(session)
Traceback (most recent call last):
[...]

However, if I import alchtest before turbogears.database.session, it gets the 
"magic" behavior:

>>> import alchtest
>>> from turbogears.database import session
>>> alchtest.foo(session)
<alchtest.Package object at 0x1dc5390>

In this situation, I have no idea what happens with the SQLite settings I 
configured in dev.cfg, whether they were replaced or somehow augmented so that 
both databases are now bound to the session.

I just wanted to follow up with this to warn future Googlers about the 
unexpected results.
-- 
Kirk Strauser

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to