diff --git a/ckanext/datastore/db.py b/ckanext/datastore/db.py index a084a9ee8a8..28326b0d1cb 100644 --- a/ckanext/datastore/db.py +++ b/ckanext/datastore/db.py @@ -113,7 +113,7 @@ def _validate_int(i, field_name, non_negative=False): }) -def _get_engine(context, data_dict): +def _get_engine(data_dict): '''Get either read or write engine.''' connection_url = data_dict['connection_url'] engine = _engines.get(connection_url) @@ -140,7 +140,7 @@ def _cache_types(context): import pylons data_dict = {'connection_url': pylons.config['ckan.datastore.write_url']} - engine = _get_engine(None, data_dict) + engine = _get_engine(data_dict) with engine.begin() as connection: connection.execute('CREATE TYPE "nested" AS (json {0}, extra text)' .format('json' if native_json else 'text')) @@ -946,7 +946,7 @@ def create(context, data_dict): Any error results in total failure! For now pass back the actual error. Should be transactional. ''' - engine = _get_engine(context, data_dict) + engine = _get_engine(data_dict) context['connection'] = engine.connect() timeout = context.get('query_timeout', 60000) _cache_types(context) @@ -1002,7 +1002,7 @@ def upsert(context, data_dict): Any error results in total failure! For now pass back the actual error. Should be transactional. ''' - engine = _get_engine(context, data_dict) + engine = _get_engine(data_dict) context['connection'] = engine.connect() timeout = context.get('query_timeout', 60000) @@ -1038,7 +1038,7 @@ def upsert(context, data_dict): def delete(context, data_dict): - engine = _get_engine(context, data_dict) + engine = _get_engine(data_dict) context['connection'] = engine.connect() _cache_types(context) @@ -1071,7 +1071,7 @@ def delete(context, data_dict): def search(context, data_dict): - engine = _get_engine(context, data_dict) + engine = _get_engine(data_dict) context['connection'] = engine.connect() timeout = context.get('query_timeout', 60000) _cache_types(context) @@ -1102,7 +1102,7 @@ def search(context, data_dict): def search_sql(context, data_dict): - engine = _get_engine(context, data_dict) + engine = _get_engine(data_dict) context['connection'] = engine.connect() timeout = context.get('query_timeout', 60000) _cache_types(context) diff --git a/ckanext/datastore/logic/action.py b/ckanext/datastore/logic/action.py index 1b4d323e7f2..aebc96df283 100644 --- a/ckanext/datastore/logic/action.py +++ b/ckanext/datastore/logic/action.py @@ -114,7 +114,7 @@ def datastore_upsert(context, data_dict): resources_sql = sqlalchemy.text(u'''SELECT 1 FROM "_table_metadata" WHERE name = :id AND alias_of IS NULL''') - results = db._get_engine(None, data_dict).execute(resources_sql, id=res_id) + results = db._get_engine(data_dict).execute(resources_sql, id=res_id) res_exists = results.rowcount > 0 if not res_exists: @@ -153,7 +153,7 @@ def datastore_delete(context, data_dict): resources_sql = sqlalchemy.text(u'''SELECT 1 FROM "_table_metadata" WHERE name = :id AND alias_of IS NULL''') - results = db._get_engine(None, data_dict).execute(resources_sql, id=res_id) + results = db._get_engine(data_dict).execute(resources_sql, id=res_id) res_exists = results.rowcount > 0 if not res_exists: @@ -228,7 +228,7 @@ def datastore_search(context, data_dict): pylons.config['ckan.datastore.write_url']) resources_sql = sqlalchemy.text(u'SELECT 1 FROM "_table_metadata" WHERE name = :id') - results = db._get_engine(None, data_dict).execute(resources_sql, id=res_id) + results = db._get_engine(data_dict).execute(resources_sql, id=res_id) res_exists = results.rowcount > 0 if not res_exists: diff --git a/ckanext/datastore/plugin.py b/ckanext/datastore/plugin.py index 50093d88ce4..44412d8a360 100644 --- a/ckanext/datastore/plugin.py +++ b/ckanext/datastore/plugin.py @@ -77,7 +77,6 @@ def configure(self, config): @logic.side_effect_free def new_resource_show(context, data_dict): engine = db._get_engine( - context, {'connection_url': self.read_url} ) new_data_dict = resource_show(context, data_dict) @@ -130,8 +129,7 @@ def _is_read_only_database(self): ''' Returns True if no connection has CREATE privileges on the public schema. This is the case if replication is enabled.''' for url in [self.ckan_url, self.write_url, self.read_url]: - connection = db._get_engine(None, - {'connection_url': url}).connect() + connection = db._get_engine({'connection_url': url}).connect() try: sql = u"SELECT has_schema_privilege('public', 'CREATE')" is_writable = connection.execute(sql).first()[0] @@ -155,9 +153,9 @@ def _read_connection_has_correct_privileges(self): ''' Returns True if the right permissions are set for the read only user. A table is created by the write user to test the read only user. ''' - write_connection = db._get_engine(None, + write_connection = db._get_engine( {'connection_url': self.write_url}).connect() - read_connection = db._get_engine(None, + read_connection = db._get_engine( {'connection_url': self.read_url}).connect() drop_foo_sql = u'DROP TABLE IF EXISTS _foo' @@ -202,7 +200,7 @@ def _create_alias_table(self): ''' create_alias_table_sql = u'CREATE OR REPLACE VIEW "_table_metadata" AS {0}'.format(mapping_sql) try: - connection = db._get_engine(None, + connection = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']}).connect() connection.execute(create_alias_table_sql) finally: diff --git a/ckanext/datastore/tests/test_create.py b/ckanext/datastore/tests/test_create.py index ae5621c8c18..4ab2cd59058 100644 --- a/ckanext/datastore/tests/test_create.py +++ b/ckanext/datastore/tests/test_create.py @@ -27,7 +27,6 @@ def setup_class(cls): cls.normal_user = model.User.get('annafan') import pylons engine = db._get_engine( - None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) diff --git a/ckanext/datastore/tests/test_delete.py b/ckanext/datastore/tests/test_delete.py index f4522350272..dcbc07b8ada 100644 --- a/ckanext/datastore/tests/test_delete.py +++ b/ckanext/datastore/tests/test_delete.py @@ -41,7 +41,6 @@ def setup_class(cls): import pylons engine = db._get_engine( - None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) diff --git a/ckanext/datastore/tests/test_search.py b/ckanext/datastore/tests/test_search.py index c4b58013112..c35675baa34 100644 --- a/ckanext/datastore/tests/test_search.py +++ b/ckanext/datastore/tests/test_search.py @@ -62,7 +62,6 @@ def setup_class(cls): import pylons engine = db._get_engine( - None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) diff --git a/ckanext/datastore/tests/test_unit.py b/ckanext/datastore/tests/test_unit.py index 2f0e8c0d750..c9c8a11c1c7 100644 --- a/ckanext/datastore/tests/test_unit.py +++ b/ckanext/datastore/tests/test_unit.py @@ -56,7 +56,7 @@ def test_is_valid_table_name(self): def test_pg_version_check(self): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") - engine = db._get_engine(None, + engine = db._get_engine( {'connection_url': pylons.config['sqlalchemy.url']}) connection = engine.connect() assert db._pg_version_is_at_least(connection, '8.0') diff --git a/ckanext/datastore/tests/test_upsert.py b/ckanext/datastore/tests/test_upsert.py index 2f4a48146fa..87685d99e60 100644 --- a/ckanext/datastore/tests/test_upsert.py +++ b/ckanext/datastore/tests/test_upsert.py @@ -49,7 +49,6 @@ def setup_class(cls): import pylons engine = db._get_engine( - None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) @@ -275,7 +274,6 @@ def setup_class(cls): import pylons engine = db._get_engine( - None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) @@ -382,7 +380,6 @@ def setup_class(cls): import pylons engine = db._get_engine( - None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))