From 3bf977901f6fea9aecbe006d8a84c6276b52511a Mon Sep 17 00:00:00 2001 From: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com> Date: Fri, 29 Sep 2023 16:11:23 +0200 Subject: [PATCH] [sub]fix(app/orchestrator/resources): FunctionStatus.FUNCTION_STATUS_CREATED -> FunctionStatus.FUNCTION_STATUS_WAITING (#742) # Issue Backend FunctionStatus are not aligned with [orchestrator definitions](https://github.com/Substra/orchestrator/blob/poc-decoupled-builder/lib/asset/function.proto#L29-L36). In particular, `FunctionStatus.FUNCTION_STATUS_CREATED` leading to the following error: ```txt ValueError: 'FUNCTION_STATUS_WAITING' is not a valid FunctionStatus ``` ## Description FunctionStatus.FUNCTION_STATUS_CREATED -> FunctionStatus.FUNCTION_STATUS_WAITING ## How has this been tested? Running Camelyon benchmark on [poc-builder-flpc](https://substra.org-1.poc-builder-flpc.cg.owkin.tech/compute_plans/a420306f-5719-412b-ab9c-688b7bed9c70/tasks?page=1&ordering=-rank) environment. ## Checklist - [ ] [changelog](../CHANGELOG.md) was updated with notable changes - [ ] documentation was updated --------- Signed-off-by: Thibault Camalon <135698225+thbcmlowk@users.noreply.github.com> --- backend/api/events/sync.py | 5 +++- .../migrations/0054_alter_function_status.py | 28 +++++++++++++++++++ backend/api/tests/asset_factory.py | 2 +- .../api/tests/views/test_views_function.py | 12 ++++---- backend/orchestrator/mock.py | 2 +- backend/orchestrator/resources.py | 2 +- 6 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 backend/api/migrations/0054_alter_function_status.py diff --git a/backend/api/events/sync.py b/backend/api/events/sync.py index 5eec55a48..569c4e0db 100644 --- a/backend/api/events/sync.py +++ b/backend/api/events/sync.py @@ -390,7 +390,10 @@ def _on_create_failure_report(event: dict) -> None: if asset_type == failure_report_pb2.FAILED_ASSET_FUNCTION: # Needed as this field is only in ComputeTask - compute_task_keys = ComputeTask.objects.values_list("key", flat=True).filter(function_id=asset_key, status__in=[ComputeTask.Status.STATUS_TODO.value, ComputeTask.Status.STATUS_DOING.value]) + compute_task_keys = ComputeTask.objects.values_list("key", flat=True).filter( + function_id=asset_key, + status__in=[ComputeTask.Status.STATUS_TODO.value, ComputeTask.Status.STATUS_DOING.value], + ) for task_key in compute_task_keys: _update_computetask(key=str(task_key), failure_report={"error_type": failure_report.get("error_type")}) diff --git a/backend/api/migrations/0054_alter_function_status.py b/backend/api/migrations/0054_alter_function_status.py new file mode 100644 index 000000000..1bdab7e11 --- /dev/null +++ b/backend/api/migrations/0054_alter_function_status.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.3 on 2023-09-27 16:09 + +from django.db import migrations +from django.db import models + + +class Migration(migrations.Migration): + dependencies = [ + ("api", "0053_function_status"), + ] + + operations = [ + migrations.AlterField( + model_name="function", + name="status", + field=models.CharField( + choices=[ + ("FUNCTION_STATUS_UNKNOWN", "Function Status Unknown"), + ("FUNCTION_STATUS_WAITING", "Function Status Waiting"), + ("FUNCTION_STATUS_BUILDING", "Function Status Building"), + ("FUNCTION_STATUS_READY", "Function Status Ready"), + ("FUNCTION_STATUS_CANCELED", "Function Status Canceled"), + ("FUNCTION_STATUS_FAILED", "Function Status Failed"), + ], + max_length=64, + ), + ), + ] diff --git a/backend/api/tests/asset_factory.py b/backend/api/tests/asset_factory.py index fc15769a6..4f1b479a4 100644 --- a/backend/api/tests/asset_factory.py +++ b/backend/api/tests/asset_factory.py @@ -238,7 +238,7 @@ def create_function( creation_date=timezone.now(), owner=owner, channel=channel, - status=Function.Status.FUNCTION_STATUS_CREATED, + status=Function.Status.FUNCTION_STATUS_WAITING, **get_permissions(owner, public), ) diff --git a/backend/api/tests/views/test_views_function.py b/backend/api/tests/views/test_views_function.py index 0e624d926..ace51eedd 100644 --- a/backend/api/tests/views/test_views_function.py +++ b/backend/api/tests/views/test_views_function.py @@ -104,7 +104,7 @@ def setUp(self): "outputs": { "model": {"kind": "ASSET_MODEL", "multiple": False}, }, - "status": "FUNCTION_STATUS_CREATED", + "status": "FUNCTION_STATUS_WAITING", }, { "key": str(aggregate_function.key), @@ -136,7 +136,7 @@ def setUp(self): "outputs": { "model": {"kind": "ASSET_MODEL", "multiple": False}, }, - "status": "FUNCTION_STATUS_CREATED", + "status": "FUNCTION_STATUS_WAITING", }, { "key": str(composite_function.key), @@ -172,7 +172,7 @@ def setUp(self): "local": {"kind": "ASSET_MODEL", "multiple": False}, "shared": {"kind": "ASSET_MODEL", "multiple": False}, }, - "status": "FUNCTION_STATUS_CREATED", + "status": "FUNCTION_STATUS_WAITING", }, { "key": str(predict_function.key), @@ -207,7 +207,7 @@ def setUp(self): "outputs": { "predictions": {"kind": "ASSET_MODEL", "multiple": False}, }, - "status": "FUNCTION_STATUS_CREATED", + "status": "FUNCTION_STATUS_WAITING", }, { "key": str(metric_function.key), @@ -241,7 +241,7 @@ def setUp(self): "outputs": { "performance": {"kind": "ASSET_PERFORMANCE", "multiple": False}, }, - "status": "FUNCTION_STATUS_CREATED", + "status": "FUNCTION_STATUS_WAITING", }, ] @@ -453,7 +453,7 @@ def mock_orc_response(data): "function": data["function"], "inputs": data["inputs"], "outputs": data["outputs"], - "status": Function.Status.FUNCTION_STATUS_CREATED, + "status": Function.Status.FUNCTION_STATUS_WAITING, } function_path = os.path.join(FIXTURE_PATH, filename) diff --git a/backend/orchestrator/mock.py b/backend/orchestrator/mock.py index 84fa03ad0..1cf4f2eca 100644 --- a/backend/orchestrator/mock.py +++ b/backend/orchestrator/mock.py @@ -95,7 +95,7 @@ class Meta: function_address = factory.SubFactory(AddressFactory) inputs = {} outputs = {} - status = FunctionStatus.FUNCTION_STATUS_CREATED + status = FunctionStatus.FUNCTION_STATUS_WAITING class ComputePlanFactory(factory.Factory): diff --git a/backend/orchestrator/resources.py b/backend/orchestrator/resources.py index 2379cab52..2b1a62ea8 100644 --- a/backend/orchestrator/resources.py +++ b/backend/orchestrator/resources.py @@ -140,7 +140,7 @@ def from_grpc(cls, o: function_pb2.FunctionOutput) -> FunctionOutput: class FunctionStatus(AutoNameEnum): FUNCTION_STATUS_UNKNOWN = enum.auto() - FUNCTION_STATUS_CREATED = enum.auto() + FUNCTION_STATUS_WAITING = enum.auto() FUNCTION_STATUS_BUILDING = enum.auto() FUNCTION_STATUS_READY = enum.auto() FUNCTION_STATUS_CANCELED = enum.auto()