Skip to content

Commit

Permalink
[#1725] Datastore must be the first IDatastore plugin loaded
Browse files Browse the repository at this point in the history
This allows extensions to rely on it running before them.
  • Loading branch information
vitorbaptista committed Jun 10, 2014
1 parent b4befdd commit df8c1af
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ckanext/datastore/plugin.py
Expand Up @@ -39,6 +39,18 @@ class DatastorePlugin(p.SingletonPlugin):
legacy_mode = False
resource_show_action = None

def __init__(self, *args, **kwargs):
idatastore_extensions = p.PluginImplementations(interfaces.IDatastore)
idatastore_extensions = idatastore_extensions.extensions()

if idatastore_extensions and idatastore_extensions[0] != self:
msg = ('The "datastore" extension must be the first IDatastore '
'extension loaded. Change the order it is loaded in '
'"ckan.plugins" in your CKAN .ini file and try again.')
raise DatastoreException(msg)

super(self.__class__, self).__init__(*args, **kwargs)

def configure(self, config):
self.config = config
# check for ckan.datastore.write_url and ckan.datastore.read_url
Expand Down
27 changes: 27 additions & 0 deletions ckanext/datastore/tests/test_plugin.py
@@ -0,0 +1,27 @@
import nose

import ckan.plugins as p
import ckanext.datastore.plugin as datastore


assert_raises = nose.tools.assert_raises


class TestPlugin(object):
@classmethod
def setup(cls):
if p.plugin_loaded('datastore'):
p.unload('datastore')
if p.plugin_loaded('sample_datastore_plugin'):
p.unload('sample_datastore_plugin')

def test_loading_datastore_first_works(self):
p.load('datastore')
p.load('sample_datastore_plugin')
p.unload('sample_datastore_plugin')
p.unload('datastore')

def test_loading_datastore_last_doesnt_work(self):
p.load('sample_datastore_plugin')
assert_raises(datastore.DatastoreException, p.load, 'datastore')
p.unload('sample_datastore_plugin')

0 comments on commit df8c1af

Please sign in to comment.