[ckan-changes] commit/ckan: dread: [controllers]: #1290 Better erro when database has not been initialised.

Bitbucket commits-noreply at bitbucket.org
Thu Aug 25 11:10:03 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/484e50c4f989/
changeset:   484e50c4f989
user:        dread
date:        2011-08-25 13:03:56
summary:     [controllers]: #1290 Better erro when database has not been initialised.
affected #:  2 files (1.0 KB)

--- a/ckan/controllers/home.py	Wed Aug 24 18:43:51 2011 +0100
+++ b/ckan/controllers/home.py	Thu Aug 25 12:03:56 2011 +0100
@@ -3,6 +3,7 @@
 
 from pylons import cache, config
 from genshi.template import NewTextTemplate
+import sqlalchemy.exc
 
 from ckan.authz import Authorizer
 from ckan.logic import NotAuthorized
@@ -26,6 +27,18 @@
             check_access('site_read',context)
         except NotAuthorized:
             abort(401, _('Not authorized to see this page'))
+        except (sqlalchemy.exc.ProgrammingError,
+                sqlalchemy.exc.OperationalError), e:
+            # postgres and sqlite errors for missing tables
+            msg = str(e)
+            if ('relation' in msg and 'does not exist' in msg) or \
+                   ('no such table' in msg) :
+                # table missing, major database problem
+                abort(503, _('This site is currently off-line. Database is not initialised.'))
+                # TODO: send an email to the admin person (#1285)
+            else:
+                raise
+            
 
     @staticmethod
     def _home_cache_key(latest_revision_id=None):


--- a/ckan/tests/functional/test_home.py	Wed Aug 24 18:43:51 2011 +0100
+++ b/ckan/tests/functional/test_home.py	Thu Aug 25 12:03:56 2011 +0100
@@ -137,3 +137,18 @@
             offset = url_for('home')
             res = self.app.get(offset)
             res = res.click('English')
+
+class TestDatabaseNotInitialised(TestController):
+    @classmethod
+    def setup_class(cls):
+        PylonsTestCase.setup_class()
+        model.repo.clean_db()
+
+    @classmethod
+    def teardown_class(self):
+        model.repo.rebuild_db()
+
+    def test_home_page(self):
+        offset = url_for('home')
+        res = self.app.get(offset, status=503)
+        assert 'This site is currently off-line. Database is not initialised.' in res

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list