changeset 1300:882ac77dc709 beta

fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 02 May 2011 12:40:57 +0200
parents 8eda822931c9
children 7e75af301842
files rhodecode/config/environment.py rhodecode/lib/__init__.py
diffstat 2 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/environment.py	Mon May 02 11:45:54 2011 +0200
+++ b/rhodecode/config/environment.py	Mon May 02 12:40:57 2011 +0200
@@ -6,18 +6,18 @@
 from mako.lookup import TemplateLookup
 from pylons.configuration import PylonsConfig
 from pylons.error import handle_mako_error
-from sqlalchemy import engine_from_config
 
 import rhodecode.lib.app_globals as app_globals
 import rhodecode.lib.helpers
 
 from rhodecode.config.routing import make_map
 from rhodecode.lib import celerypylons
+from rhodecode.lib import engine_from_config
+from rhodecode.lib.timerproxy import TimerProxy
 from rhodecode.lib.auth import set_available_permissions
 from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config
 from rhodecode.model import init_model
 from rhodecode.model.scm import ScmModel
-from rhodecode.lib.timerproxy import TimerProxy
 
 log = logging.getLogger(__name__)
 
--- a/rhodecode/lib/__init__.py	Mon May 02 11:45:54 2011 +0200
+++ b/rhodecode/lib/__init__.py	Mon May 02 12:40:57 2011 +0200
@@ -79,3 +79,22 @@
         u_str = unicode(_str, from_encoding, 'replace')
 
     return u_str
+
+
+def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs):
+    """
+    Custom engine_from_config functions that makes sure we use NullPool for
+    file based sqlite databases. This prevents errors on sqlite.
+    
+    """
+    from sqlalchemy import engine_from_config as efc
+    from sqlalchemy.pool import NullPool
+
+    url = configuration[prefix + 'url']
+
+    if url.startswith('sqlite'):
+        kwargs.update({'poolclass':NullPool})
+
+    return efc(configuration, prefix, **kwargs)
+
+