Check self.dbapi.initialized for firebird.py
I have a use case where one web application is using kinterbasdb directly and another is using sqlalchemy, both under mod_wsgi. Numerous attempts at different configuration scenarios led me to run both applications with the WSGIApplicationGroup = ${GLOBAL} setting in the conf file for httpd. It appears that firebird.py does not check if kinterbasdb has alread been initialized before making its call to init. It only checks if it has attempted to initialize.
This is the stack trace I would inevitably see:
cherrypy.server.start(init_only=True, server_class=None)
File "/usr/lib/python2.4/site-packages/cherrypy/_cpserver.py", line 72, in start
Engine.start(self)
File "/usr/lib/python2.4/site-packages/cherrypy/_cpengine.py", line 106, in start
self._start()
File "/usr/lib/python2.4/site-packages/cherrypy/_cpserver.py", line 78, in _start
Engine._start(self)
File "/usr/lib/python2.4/site-packages/cherrypy/_cpengine.py", line 110, in _start
func()
File "/usr/lib/python2.4/site-packages/turbogears/startup.py", line 227, in startTurboGears
database.get_engine()
File "/usr/lib/python2.4/site-packages/turbogears/database.py", line 45, in get_engine
_engine = sqlalchemy.create_engine(dburi, **alch_args)
File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/__init__.py", line 173, in create_engine
return strategy.create(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/strategies.py", line 70, in create
(cargs, cparams) = dialect.create_connect_args(u)
File "/usr/lib/python2.4/site-packages/sqlalchemy/databases/firebird.py", line 294, in create_connect_args
self.dbapi.init(type_conv=type_conv, concurrency_level=concurrency_level)
File "/usr/lib/python2.4/site-packages/kinterbasdb/__init__.py", line 272, in init
_k.concurrency_level_set(concurrency_level)
ProgrammingError: (0, 'The concurrency level cannot be changed once it has been set. Use kinterbasdb.init(concurrency_level=?) to set the concurrency level legally.')
I needed to add this:
diff -Naur SQLAlchemy-0.4.7/lib/sqlalchemy/databases/firebird.py SQLAlchemy-0.4.7.new/lib/sqlalchemy/databases/firebird.py
--- SQLAlchemy-0.4.7/lib/sqlalchemy/databases/firebird.py 2008-07-26 12:43:52.000000000 -0400
+++ SQLAlchemy-0.4.7.new/lib/sqlalchemy/databases/firebird.py 2008-10-01 10:51:22.000000000 -0400
@@ -291,7 +291,8 @@
global _initialized_kb
if not _initialized_kb and self.dbapi is not None:
_initialized_kb = True
- self.dbapi.init(type_conv=type_conv, concurrency_level=concurrency_level)
+ if not self.dbapi.initialized:
+ self.dbapi.init(type_conv=type_conv, concurrency_level=concurrency_level)
return ([], opts)
def create_execution_context(self, *args, **kwargs):
This configuration and patch allowed me to run both apps, one with kinterbasdb being used directly, and another with sqlalchemy. I could find no other way to do this. If there is a better method, I could not find it.
Comments (5)
-
-
repo owner its up to you guys if you want to implement. You can say
getattr(self.dbapi, 'initialized', False)
for a more version neutral approach. -
repo owner -
- changed status to resolved
Fixed by 6353. This should be merged back on the 0.5.x series.
-
repo owner - removed milestone
Removing milestone: 0.5.xx (automated comment)
- Log in to comment
While this is simple enough, at the time I didn't use the
initialized
attribute on the module because at least one of my machines was using a slightly old kinterbasdb that didn't carry that flag: http://kinterbasdb.cvs.sourceforge.net/viewvc/kinterbasdb/Kinterbasdb-3.0/init.py?ec052c6a1f1fb0236bd367c510d82f076cb67bc9=1.95&76ed6f7ab6823d0906286026a40e6a3fca7ada27=1.96It may be very well spreaded nowadays...