Re: session_context and multiple SA databases
On Jan 17, 2007, at 6:19 AM, Max Ischenko wrote: TypeError: No configuration has been registered for this process or thread Your CONFIG object is automatically setup for you in paster shell, it won't be when running it from your own script. Can you please explain how should I setup CONFIG then? I have tried to add the following to my tests/__init__.py: from paste.deploy import loadapp, appconfig, CONFIG import paste.fixture app_conf = appconfig('config:development.ini', relative_to=conf_dir) CONFIG.push_thread_config({'app_conf':app_conf}) assert CONFIG['app_conf']['sqlalchemy.dburi'] But it looks like doupy.lib.database imported earlier than this is executed so I still have the same error. Another issue. If I use DynamicMetadata, as recommended in QuickWiki tutorial, how am I supposed to connect it to correct session_context? Do I need to create engine explicitly (via create_engine) and then call meta.connect(engine)? If so, when this should happen? Yes, you do need to connect the engine explicitly if you want to use metadata functions, such as create_all. Take a look at the QuickWiki's websetup.py. It has examples of both setting up the CONFIG object and using metadata.create_all. I have seen websetup.py. But where I have to put this code inside my application? Thanks, Max. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: session_context and multiple SA databases
You'll want to setup another session_context similar to how the main one is setup in pylons.database. For example, in one of your models modules: from paste.deploy import CONFIG from sqlalchemy.ext import sessioncontext from pylons.database import app_scope, make_session dburi2 = CONFIG['app_conf']['sqlachemy.dburi2'] session_context2 = sessioncontext.SessionContext(lambda: make_session (dburi2), scopefunc=app_scope) It works, at least if I verify with paster shell. But I tried to write a simple test to assert this behavior and got a strange error: File /home/max/projects/dou-trunk/site/doupy/doupy/tests/functional/test_db_conn.py, line 2, in ? from doupy.lib.database import * File /home/max/projects/dou-trunk/site/doupy/doupy/lib/database.py, line 15, in ? dburi = CONFIG['app_conf']['sqlalchemy.dburi'] File /usr/lib/python2.4/site-packages/PasteDeploy-1.0-py2.4.egg/paste/deploy/config.py, line 119, in __getitem__ raise TypeError( TypeError: No configuration has been registered for this process or thread --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: session_context and multiple SA databases
Another issue. If I use DynamicMetadata, as recommended in QuickWiki tutorial, how am I supposed to connect it to correct session_context? Do I need to create engine explicitly (via create_engine) and then call meta.connect(engine)? If so, when this should happen? Max. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: session_context and multiple SA databases
On Jan 17, 2007, at 6:19 AM, Max Ischenko wrote: It works, at least if I verify with paster shell. But I tried to write a simple test to assert this behavior and got a strange error: File /home/max/projects/dou-trunk/site/doupy/doupy/tests/functional/ test_db_conn.py, line 2, in ? from doupy.lib.database import * File /home/max/projects/dou-trunk/site/doupy/doupy/lib/database.py, line 15, in ? dburi = CONFIG['app_conf']['sqlalchemy.dburi'] File /usr/lib/python2.4/site-packages/PasteDeploy-1.0-py2.4.egg/paste/ deploy/config.py, line 119, in __getitem__ raise TypeError( TypeError: No configuration has been registered for this process or thread Your CONFIG object is automatically setup for you in paster shell, it won't be when running it from your own script. Another issue. If I use DynamicMetadata, as recommended in QuickWiki tutorial, how am I supposed to connect it to correct session_context? Do I need to create engine explicitly (via create_engine) and then call meta.connect(engine)? If so, when this should happen? Yes, you do need to connect the engine explicitly if you want to use metadata functions, such as create_all. Take a look at the QuickWiki's websetup.py. It has examples of both setting up the CONFIG object and using metadata.create_all. -- Philip Jenvey --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
session_context and multiple SA databases
Hello, What is a recommended way to work with multiple database through SqlAlachemy? I can use pylons.database.make_session() to create session explicitly but what about automatic management (akin to what session_context provides)? Max --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---
Re: session_context and multiple SA databases
On Jan 16, 2007, at 5:58 AM, Max Ischenko wrote: Hello, What is a recommended way to work with multiple database through SqlAlachemy? I can use pylons.database.make_session() to create session explicitly but what about automatic management (akin to what session_context provides)? You'll want to setup another session_context similar to how the main one is setup in pylons.database. For example, in one of your models modules: from paste.deploy import CONFIG from sqlalchemy.ext import sessioncontext from pylons.database import app_scope, make_session dburi2 = CONFIG['app_conf']['sqlachemy.dburi2'] session_context2 = sessioncontext.SessionContext(lambda: make_session (dburi2), scopefunc=app_scope) -- Philip Jenvey --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups pylons-discuss group. To post to this group, send email to pylons-discuss@googlegroups.com 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 -~--~~~~--~~--~--~---