Changeset - 882ac77dc709
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 15 years ago 2011-05-02 12:40:57
marcin@python-works.com
fixed problem with `Cannot operate on a closed database` error, by forcing NullPool when using sqlite database.
2 files changed with 21 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/environment.py
Show inline comments
 
@@ -6,18 +6,18 @@ import logging
 
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__)
 

	
rhodecode/lib/__init__.py
Show inline comments
 
@@ -79,3 +79,22 @@ def safe_unicode(_str, from_encoding='ut
 
        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)
 

	
 

	
0 comments (0 inline, 0 general)