diff --git a/swh/core/cli/db.py b/swh/core/cli/db.py --- a/swh/core/cli/db.py +++ b/swh/core/cli/db.py @@ -198,16 +198,14 @@ datastore_factory = getattr(import_swhmodule(module), "get_datastore", None) if datastore_factory: datastore = datastore_factory(**cfg) - try: - get_current_version = datastore.get_current_version - except AttributeError: + if not hasattr(datastore, "current_version"): logger.warning( - "Datastore %s does not implement the " - "'get_current_version()' method", + "Datastore %s does not declare the " + "'current_version' attribute", datastore, ) else: - code_version = get_current_version() + code_version = datastore.current_version logger.info( "Initializing database version to %s from the %s datastore", code_version, @@ -299,7 +297,7 @@ datastore_factory = getattr(import_swhmodule(db_module), "get_datastore", None) if datastore_factory: datastore = datastore_factory(**cfg) - code_version = datastore.get_current_version() + code_version = datastore.current_version click.secho( f"current code version: {code_version}", fg="green" if code_version == db_version else "red", @@ -387,7 +385,7 @@ "You cannot use this command on old-style datastore backend {db_module}" ) datastore = datastore_factory(**cfg) - ds_version = datastore.get_current_version() + ds_version = datastore.current_version if to_version is None: to_version = ds_version if to_version > ds_version: diff --git a/swh/core/db/tests/conftest.py b/swh/core/db/tests/conftest.py --- a/swh/core/db/tests/conftest.py +++ b/swh/core/db/tests/conftest.py @@ -35,7 +35,7 @@ set to `` and __file__ pointing to `data//__init__.py`. The Mock object also defines a `get_datastore()` attribute on which the - `get_current_version()` exists and will return 42. + `current_version` attribute is set to 42. Typical usage:: @@ -54,7 +54,7 @@ dirname = modname.split(".", 1)[1] def get_datastore(*args, **kw): - return mock(get_current_version=lambda: 42) + return mock(current_version=42) return mock( __name__=modname, diff --git a/swh/core/db/tests/test_cli.py b/swh/core/db/tests/test_cli.py --- a/swh/core/db/tests/test_cli.py +++ b/swh/core/db/tests/test_cli.py @@ -254,7 +254,7 @@ dirname = modname.split(".", 1)[1] def get_datastore(cls, **kw): - return mocker.MagicMock(get_current_version=lambda: current_version) + return mocker.MagicMock(current_version=current_version) return mocker.MagicMock( __name__=modname,