[repost, with more details] There is one other way that seems to work (I am using declarative_base () and too lazy to define Table() mappings): -add the schema value read from app_conf to app_globals in environment.py -move the ORM classes to a new module (essentially, move it out of__init__.py so that the dependency that broke the initialization is eliminated). Obviously, you'll need to update the ORM class imports in your controllers and tests as appropriate. -import yourapp.lib.app_globals in the new module
This seems to work (I just ran nosetests as well). Being new to pylons, I may have missed something crucial, however. -gsk On Sep 8, 11:15 pm, gsk <[email protected]> wrote: > There is one other way that seems to work (I am using declarative_base > () and too lazy to define Table() mappings): > -set the schema variable to app_globals in environment.py > app_globals.novadb_schema = app_conf.get('novadb_schema') > init_model(engine) > -move the ORM classes to a new module (essentially, move it out of > __init__.py so that the dependency is eliminated). Obviously, you'll > need to update the ORM class imports in your controllers and tests as > appropriate. > - > On Sep 8, 9:28 pm, Mike Orr <[email protected]> wrote: > > > On Tue, Sep 8, 2009 at 1:17 PM, gsk<[email protected]> wrote: > > > > Hi, > > > Newbie question: I am using SqlAlchemy for Postgresql backend. I have > > > setup a schema in the db where all the tables I need exist. So, I have > > > the ORM class as below where I would dynamically pass the value for > > > the schema: > > > > class Foo(Base): > > > __tablename__ = 'foo_table' > > > __table_args__ = {'schema': someschema} > > > > ... > > > > I have put the db schema value in test.ini file hoping to use > > > pylons.config. But, apparently, Pylons config object is not yet setup > > > when model/__init__.py is initialized. Any suggestions on how I could > > > get around this? (I've hardcoded the schema at the moment but need to > > > parameterize as the dev and test environments use different postgresql > > > schema spaces) > > > Er, I'm not sure if you can do that. The normal configuration is for > > environment.py to call init_model(), at which point the configuration > > is ready. (Although most init_model calls pass the needed values > > directly as arguments.) But in this case you're trying to set > > something at the class level before init_model is called. init_model > > could change the table object dynamically, if that's possible. > > > The general workaround is to put the table definitions inside > > init_model, and have init_model assign them to global variables. > > People do that to map autoloaded tables to ORM classes. > > > -- > > Mike Orr <[email protected]> > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
