Skip to content

Commit

Permalink
[#907] Remove unused argument context from _get_engine
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed May 27, 2013
1 parent 4d95bbc commit 05e6e18
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 23 deletions.
14 changes: 7 additions & 7 deletions ckanext/datastore/db.py
Expand Up @@ -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)
Expand All @@ -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'))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions ckanext/datastore/logic/action.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions ckanext/datastore/plugin.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion ckanext/datastore/tests/test_create.py
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion ckanext/datastore/tests/test_delete.py
Expand Up @@ -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))
Expand Down
1 change: 0 additions & 1 deletion ckanext/datastore/tests/test_search.py
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion ckanext/datastore/tests/test_unit.py
Expand Up @@ -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')
Expand Down
3 changes: 0 additions & 3 deletions ckanext/datastore/tests/test_upsert.py
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 05e6e18

Please sign in to comment.