From 4fc40eb9c82025a3a3b5251276a0fc4771398c84 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 18 May 2022 09:08:26 +0900 Subject: [PATCH] Avoid save labels if there is no corresponding example --- backend/data_import/pipeline/labels.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/data_import/pipeline/labels.py b/backend/data_import/pipeline/labels.py index a2d3a5b2..6bac0446 100644 --- a/backend/data_import/pipeline/labels.py +++ b/backend/data_import/pipeline/labels.py @@ -41,8 +41,11 @@ class Labels(abc.ABC): return {example.uuid: example for example in examples} def save(self, user, **kwargs): + uuid_to_example = self.uuid_to_example labels = [ - label.create(user, self.uuid_to_example[label.example_uuid], self.types, **kwargs) for label in self.labels + label.create(user, uuid_to_example[label.example_uuid], self.types, **kwargs) + for label in self.labels + if label.example_uuid in uuid_to_example ] self.label_model.objects.bulk_create(labels)