We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Tolerate missing system_info table
If you have an old or incomplete database some commands (such as db clean) will fail because they can't find the system_info table.

```python-traceback
$ cd ckan; paster db clean -c test-core.ini; paster db init -c test-core.ini
Traceback (most recent call last):
  File "/home/ubuntu/virtualenvs/venv-system/bin/paster", line 11, in <module>
    sys.exit(run())
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/paste/script/command.py", line 102, in run
    invoke(command, command_name, options, args[1:])
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/paste/script/command.py", line 141, in invoke
    exit_code = runner.run(args)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/paste/script/command.py", line 236, in run
    result = self.command()
  File "/home/ubuntu/ckanext-scheming/ckan/ckan/lib/cli.py", line 217, in command
    self._load_config(cmd!='upgrade')
  File "/home/ubuntu/ckanext-scheming/ckan/ckan/lib/cli.py", line 161, in _load_config
    load_environment(conf.global_conf, conf.local_conf)
  File "/home/ubuntu/ckanext-scheming/ckan/ckan/config/environment.py", line 99, in load_environment
    app_globals.reset()
  File "/home/ubuntu/ckanext-scheming/ckan/ckan/lib/app_globals.py", line 172, in reset
    get_config_value(key)
  File "/home/ubuntu/ckanext-scheming/ckan/ckan/lib/app_globals.py", line 139, in get_config_value
    value = model.get_system_info(key)
  File "/home/ubuntu/ckanext-scheming/ckan/ckan/model/system_info.py", line 56, in get_system_info
    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2334, in first
    ret = list(self[0:1])
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2201, in __getitem__
    return list(res)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2405, in __iter__
    return self._execute_and_instances(context)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2420, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 727, in execute
    return meth(self, multiparams, params)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py", line 322, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 824, in _execute_clauseelement
    compiled_sql, distilled_params
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 954, in _execute_context
    context)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1116, in _handle_dbapi_exception
    exc_info
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 189, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 947, in _execute_context
    context)
  File "/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 435, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) column system_info.state does not exist
LINE 1: ...info_key, system_info.value AS system_info_value, system_inf...
                                                             ^
 'SELECT system_info.id AS system_info_id, system_info.key AS system_info_key, system_info.value AS system_info_value, system_info.state AS system_info_state, system_info.revision_id AS system_info_revision_id \nFROM system_info \nWHERE system_info.key = %(key_1)s \n LIMIT %(param_1)s' {'param_1': 1, 'key_1': 'ckan.site_description'}
```

This change treats a missing system_info table the same as no overridden configuration.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `ckan/model/system_info.py`
Content:
```
1 # encoding: utf-8
2 
3 '''
4 The system_info table and SystemInfo mapped class store runtime-editable
5 configuration options.
6 
7 For more details, check :doc:`maintaining/configuration`.
8 '''
9 
10 from sqlalchemy import types, Column, Table
11 
12 import vdm.sqlalchemy
13 import meta
14 import core
15 import domain_object
16 
17 __all__ = ['system_info_revision_table', 'system_info_table', 'SystemInfo',
18            'SystemInfoRevision', 'get_system_info', 'set_system_info']
19 
20 system_info_table = Table(
21     'system_info', meta.metadata,
22     Column('id', types.Integer(),  primary_key=True, nullable=False),
23     Column('key', types.Unicode(100), unique=True, nullable=False),
24     Column('value', types.UnicodeText),
25 )
26 
27 vdm.sqlalchemy.make_table_stateful(system_info_table)
28 system_info_revision_table = core.make_revisioned_table(system_info_table)
29 
30 
31 class SystemInfo(vdm.sqlalchemy.RevisionedObjectMixin,
32                  vdm.sqlalchemy.StatefulObjectMixin,
33                  domain_object.DomainObject):
34 
35     def __init__(self, key, value):
36 
37         super(SystemInfo, self).__init__()
38 
39         self.key = key
40         self.value = unicode(value)
41 
42 
43 meta.mapper(SystemInfo, system_info_table,
44             extension=[
45                 vdm.sqlalchemy.Revisioner(system_info_revision_table),
46                 ])
47 
48 vdm.sqlalchemy.modify_base_object_mapper(SystemInfo, core.Revision, core.State)
49 SystemInfoRevision = vdm.sqlalchemy.create_object_version(meta.mapper,
50                                                           SystemInfo,
51                                                           system_info_revision_table)
52 
53 
54 def get_system_info(key, default=None):
55     ''' get data from system_info table '''
56     obj = meta.Session.query(SystemInfo).filter_by(key=key).first()
57     if obj:
58         return obj.value
59     else:
60         return default
61 
62 
63 def delete_system_info(key, default=None):
64     ''' delete data from system_info table '''
65     obj = meta.Session.query(SystemInfo).filter_by(key=key).first()
66     if obj:
67         meta.Session.delete(obj)
68         meta.Session.commit()
69 
70 
71 def set_system_info(key, value):
72     ''' save data in the system_info table '''
73     obj = None
74     obj = meta.Session.query(SystemInfo).filter_by(key=key).first()
75     if obj and obj.value == unicode(value):
76         return
77     if not obj:
78         obj = SystemInfo(key, value)
79     else:
80         obj.value = unicode(value)
81 
82     from ckan.model import repo
83     rev = repo.new_revision()
84     rev.message = 'Set {0} setting in system_info table'.format(key)
85     meta.Session.add(obj)
86     meta.Session.commit()
87 
88     return True
89
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/ckan/model/system_info.py b/ckan/model/system_info.py
--- a/ckan/model/system_info.py
+++ b/ckan/model/system_info.py
@@ -53,11 +53,14 @@
 
 def get_system_info(key, default=None):
     ''' get data from system_info table '''
-    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()
-    if obj:
-        return obj.value
-    else:
-        return default
+    from sqlalchemy.exc import ProgrammingError
+    try:
+        obj = meta.Session.query(SystemInfo).filter_by(key=key).first()
+        if obj:
+            return obj.value
+    except ProgrammingError:
+        meta.Session.rollback()
+    return default
 
 
 def delete_system_info(key, default=None):

{"golden_diff": "diff --git a/ckan/model/system_info.py b/ckan/model/system_info.py\n--- a/ckan/model/system_info.py\n+++ b/ckan/model/system_info.py\n@@ -53,11 +53,14 @@\n \n def get_system_info(key, default=None):\n     ''' get data from system_info table '''\n-    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n-    if obj:\n-        return obj.value\n-    else:\n-        return default\n+    from sqlalchemy.exc import ProgrammingError\n+    try:\n+        obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n+        if obj:\n+            return obj.value\n+    except ProgrammingError:\n+        meta.Session.rollback()\n+    return default\n \n \n def delete_system_info(key, default=None):\n", "issue": "Tolerate missing system_info table\nIf you have an old or incomplete database some commands (such as db clean) will fail because they can't find the system_info table.\r\n\r\n```python-traceback\r\n$ cd ckan; paster db clean -c test-core.ini; paster db init -c test-core.ini\r\nTraceback (most recent call last):\r\n  File \"/home/ubuntu/virtualenvs/venv-system/bin/paster\", line 11, in <module>\r\n    sys.exit(run())\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/paste/script/command.py\", line 102, in run\r\n    invoke(command, command_name, options, args[1:])\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/paste/script/command.py\", line 141, in invoke\r\n    exit_code = runner.run(args)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/paste/script/command.py\", line 236, in run\r\n    result = self.command()\r\n  File \"/home/ubuntu/ckanext-scheming/ckan/ckan/lib/cli.py\", line 217, in command\r\n    self._load_config(cmd!='upgrade')\r\n  File \"/home/ubuntu/ckanext-scheming/ckan/ckan/lib/cli.py\", line 161, in _load_config\r\n    load_environment(conf.global_conf, conf.local_conf)\r\n  File \"/home/ubuntu/ckanext-scheming/ckan/ckan/config/environment.py\", line 99, in load_environment\r\n    app_globals.reset()\r\n  File \"/home/ubuntu/ckanext-scheming/ckan/ckan/lib/app_globals.py\", line 172, in reset\r\n    get_config_value(key)\r\n  File \"/home/ubuntu/ckanext-scheming/ckan/ckan/lib/app_globals.py\", line 139, in get_config_value\r\n    value = model.get_system_info(key)\r\n  File \"/home/ubuntu/ckanext-scheming/ckan/ckan/model/system_info.py\", line 56, in get_system_info\r\n    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py\", line 2334, in first\r\n    ret = list(self[0:1])\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py\", line 2201, in __getitem__\r\n    return list(res)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py\", line 2405, in __iter__\r\n    return self._execute_and_instances(context)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py\", line 2420, in _execute_and_instances\r\n    result = conn.execute(querycontext.statement, self._params)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 727, in execute\r\n    return meth(self, multiparams, params)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/sql/elements.py\", line 322, in _execute_on_connection\r\n    return connection._execute_clauseelement(self, multiparams, params)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 824, in _execute_clauseelement\r\n    compiled_sql, distilled_params\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 954, in _execute_context\r\n    context)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 1116, in _handle_dbapi_exception\r\n    exc_info\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py\", line 189, in raise_from_cause\r\n    reraise(type(exception), exception, tb=exc_tb)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 947, in _execute_context\r\n    context)\r\n  File \"/home/ubuntu/virtualenvs/venv-system/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py\", line 435, in do_execute\r\n    cursor.execute(statement, parameters)\r\nsqlalchemy.exc.ProgrammingError: (ProgrammingError) column system_info.state does not exist\r\nLINE 1: ...info_key, system_info.value AS system_info_value, system_inf...\r\n                                                             ^\r\n 'SELECT system_info.id AS system_info_id, system_info.key AS system_info_key, system_info.value AS system_info_value, system_info.state AS system_info_state, system_info.revision_id AS system_info_revision_id \\nFROM system_info \\nWHERE system_info.key = %(key_1)s \\n LIMIT %(param_1)s' {'param_1': 1, 'key_1': 'ckan.site_description'}\r\n```\r\n\r\nThis change treats a missing system_info table the same as no overridden configuration.\n", "before_files": [{"content": "# encoding: utf-8\n\n'''\nThe system_info table and SystemInfo mapped class store runtime-editable\nconfiguration options.\n\nFor more details, check :doc:`maintaining/configuration`.\n'''\n\nfrom sqlalchemy import types, Column, Table\n\nimport vdm.sqlalchemy\nimport meta\nimport core\nimport domain_object\n\n__all__ = ['system_info_revision_table', 'system_info_table', 'SystemInfo',\n           'SystemInfoRevision', 'get_system_info', 'set_system_info']\n\nsystem_info_table = Table(\n    'system_info', meta.metadata,\n    Column('id', types.Integer(),  primary_key=True, nullable=False),\n    Column('key', types.Unicode(100), unique=True, nullable=False),\n    Column('value', types.UnicodeText),\n)\n\nvdm.sqlalchemy.make_table_stateful(system_info_table)\nsystem_info_revision_table = core.make_revisioned_table(system_info_table)\n\n\nclass SystemInfo(vdm.sqlalchemy.RevisionedObjectMixin,\n                 vdm.sqlalchemy.StatefulObjectMixin,\n                 domain_object.DomainObject):\n\n    def __init__(self, key, value):\n\n        super(SystemInfo, self).__init__()\n\n        self.key = key\n        self.value = unicode(value)\n\n\nmeta.mapper(SystemInfo, system_info_table,\n            extension=[\n                vdm.sqlalchemy.Revisioner(system_info_revision_table),\n                ])\n\nvdm.sqlalchemy.modify_base_object_mapper(SystemInfo, core.Revision, core.State)\nSystemInfoRevision = vdm.sqlalchemy.create_object_version(meta.mapper,\n                                                          SystemInfo,\n                                                          system_info_revision_table)\n\n\ndef get_system_info(key, default=None):\n    ''' get data from system_info table '''\n    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n    if obj:\n        return obj.value\n    else:\n        return default\n\n\ndef delete_system_info(key, default=None):\n    ''' delete data from system_info table '''\n    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n    if obj:\n        meta.Session.delete(obj)\n        meta.Session.commit()\n\n\ndef set_system_info(key, value):\n    ''' save data in the system_info table '''\n    obj = None\n    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n    if obj and obj.value == unicode(value):\n        return\n    if not obj:\n        obj = SystemInfo(key, value)\n    else:\n        obj.value = unicode(value)\n\n    from ckan.model import repo\n    rev = repo.new_revision()\n    rev.message = 'Set {0} setting in system_info table'.format(key)\n    meta.Session.add(obj)\n    meta.Session.commit()\n\n    return True\n", "path": "ckan/model/system_info.py"}], "after_files": [{"content": "# encoding: utf-8\n\n'''\nThe system_info table and SystemInfo mapped class store runtime-editable\nconfiguration options.\n\nFor more details, check :doc:`maintaining/configuration`.\n'''\n\nfrom sqlalchemy import types, Column, Table\n\nimport vdm.sqlalchemy\nimport meta\nimport core\nimport domain_object\n\n__all__ = ['system_info_revision_table', 'system_info_table', 'SystemInfo',\n           'SystemInfoRevision', 'get_system_info', 'set_system_info']\n\nsystem_info_table = Table(\n    'system_info', meta.metadata,\n    Column('id', types.Integer(),  primary_key=True, nullable=False),\n    Column('key', types.Unicode(100), unique=True, nullable=False),\n    Column('value', types.UnicodeText),\n)\n\nvdm.sqlalchemy.make_table_stateful(system_info_table)\nsystem_info_revision_table = core.make_revisioned_table(system_info_table)\n\n\nclass SystemInfo(vdm.sqlalchemy.RevisionedObjectMixin,\n                 vdm.sqlalchemy.StatefulObjectMixin,\n                 domain_object.DomainObject):\n\n    def __init__(self, key, value):\n\n        super(SystemInfo, self).__init__()\n\n        self.key = key\n        self.value = unicode(value)\n\n\nmeta.mapper(SystemInfo, system_info_table,\n            extension=[\n                vdm.sqlalchemy.Revisioner(system_info_revision_table),\n                ])\n\nvdm.sqlalchemy.modify_base_object_mapper(SystemInfo, core.Revision, core.State)\nSystemInfoRevision = vdm.sqlalchemy.create_object_version(meta.mapper,\n                                                          SystemInfo,\n                                                          system_info_revision_table)\n\n\ndef get_system_info(key, default=None):\n    ''' get data from system_info table '''\n    from sqlalchemy.exc import ProgrammingError\n    try:\n        obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n        if obj:\n            return obj.value\n    except ProgrammingError:\n        meta.Session.rollback()\n    return default\n\n\ndef delete_system_info(key, default=None):\n    ''' delete data from system_info table '''\n    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n    if obj:\n        meta.Session.delete(obj)\n        meta.Session.commit()\n\n\ndef set_system_info(key, value):\n    ''' save data in the system_info table '''\n    obj = None\n    obj = meta.Session.query(SystemInfo).filter_by(key=key).first()\n    if obj and obj.value == unicode(value):\n        return\n    if not obj:\n        obj = SystemInfo(key, value)\n    else:\n        obj.value = unicode(value)\n\n    from ckan.model import repo\n    rev = repo.new_revision()\n    rev.message = 'Set {0} setting in system_info table'.format(key)\n    meta.Session.add(obj)\n    meta.Session.commit()\n\n    return True\n", "path": "ckan/model/system_info.py"}]}