diff --git a/arkindex_worker/worker/base.py b/arkindex_worker/worker/base.py index 78b57ee3a48fb4890981ae649678a067179a8fc0..f0a571da95e2a209906e361ce498b1d9e4fa505f 100644 --- a/arkindex_worker/worker/base.py +++ b/arkindex_worker/worker/base.py @@ -196,7 +196,7 @@ class BaseWorker(object): ) # Retrieve initial configuration from API - self.config = worker_version["configuration"]["configuration"] + self.config = worker_version["configuration"].get("configuration") if "user_configuration" in worker_version["configuration"]: # Add default values (if set) to user_configuration for key, value in worker_version["configuration"][ @@ -210,8 +210,10 @@ class BaseWorker(object): self.secrets = {name: self.load_secret(name) for name in required_secrets} # Load worker run configuration when available - worker_configuration = worker_run.get("configuration", {}) - self.user_configuration = worker_configuration.get("configuration") + worker_configuration = worker_run.get("configuration") + self.user_configuration = ( + worker_configuration.get("configuration") if worker_configuration else None + ) if self.user_configuration: logger.info("Loaded user configuration from WorkerRun") # if debug mode is set to true activate debug mode in logger diff --git a/tests/test_base_worker.py b/tests/test_base_worker.py index 0cadf6816088957ecf92ca8e3b279112944d1592..a3262ee949979b3f8bc5b59fb09c8fbbe079f716 100644 --- a/tests/test_base_worker.py +++ b/tests/test_base_worker.py @@ -372,6 +372,53 @@ def test_configure_worker_run_missing_conf(mocker, monkeypatch, responses): assert worker.user_configuration is None +def test_configure_worker_run_no_worker_run_conf(mocker, monkeypatch, responses): + """ + No configuration is provided but should not crash + """ + worker = BaseWorker() + mocker.patch.object(sys, "argv", ["worker"]) + + payload = { + "id": "56785678-5678-5678-5678-567856785678", + "parents": [], + "worker_version_id": "12341234-1234-1234-1234-123412341234", + "model_version_id": None, + "dataimport_id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff", + "worker": { + "id": "deadbeef-1234-5678-1234-worker", + "name": "Fake worker", + "slug": "fake_worker", + "type": "classifier", + }, + "configuration_id": None, + "worker_version": { + "id": "12341234-1234-1234-1234-123412341234", + "worker": { + "id": "deadbeef-1234-5678-1234-worker", + "name": "Fake worker", + "slug": "fake_worker", + "type": "classifier", + }, + "revision": {"hash": "deadbeef1234"}, + "configuration": {}, + }, + "configuration": None, + "process": {"id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeffff"}, + } + responses.add( + responses.GET, + "http://testserver/api/v1/imports/workers/56785678-5678-5678-5678-567856785678/", + status=200, + body=json.dumps(payload), + content_type="application/json", + ) + worker.args = worker.parser.parse_args() + worker.configure() + + assert worker.user_configuration is None + + def test_load_missing_secret(): worker = BaseWorker() worker.api_client = MockApiClient()