From aed94c4ecaf0a86a2f6855eae8ce440aee171143 Mon Sep 17 00:00:00 2001 From: Jan Timpe Date: Fri, 11 Oct 2024 12:17:41 -0400 Subject: [PATCH] ensure is_finished and is_success are False if no associated files --- .../search_indexes/models/reparse_meta.py | 8 +++++-- .../search_indexes/test/test_reparse.py | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tdrs-backend/tdpservice/search_indexes/models/reparse_meta.py b/tdrs-backend/tdpservice/search_indexes/models/reparse_meta.py index ee882e8b8..e5d43441c 100644 --- a/tdrs-backend/tdpservice/search_indexes/models/reparse_meta.py +++ b/tdrs-backend/tdpservice/search_indexes/models/reparse_meta.py @@ -39,12 +39,16 @@ class Meta: @property def is_finished(self): """Return True if all associated ReparseFileMeta objects are finished.""" - return all([r.finished for r in self.reparse_file_metas.all()]) + if self.num_files > 0: + return all([r.finished for r in self.reparse_file_metas.all()]) + return False @property def is_success(self): """Return True if all associated ReparseFileMeta objects are successful.""" - return all([r.success for r in self.reparse_file_metas.all()]) + if self.is_finished: + return all([r.success for r in self.reparse_file_metas.all()]) + return False @property def finished_at(self): diff --git a/tdrs-backend/tdpservice/search_indexes/test/test_reparse.py b/tdrs-backend/tdpservice/search_indexes/test/test_reparse.py index 45e6d631b..afe90c859 100644 --- a/tdrs-backend/tdpservice/search_indexes/test/test_reparse.py +++ b/tdrs-backend/tdpservice/search_indexes/test/test_reparse.py @@ -494,3 +494,25 @@ def test_mm_file_counts_match(big_file): fm.finished = True fm.save() assert ReparseMeta.file_counts_match(meta_model) is True + +@pytest.mark.django_db() +def test_reparse_finished_success_false_before_file_queue(big_file): + meta_model = ReparseMeta.objects.create() + assert meta_model.is_finished is False + assert meta_model.is_success is False + + big_file.reparses.add(meta_model) + big_file.save() + assert meta_model.is_finished is False + assert meta_model.is_success is False + + fm = ReparseFileMeta.objects.get(data_file_id=big_file.pk, reparse_meta_id=meta_model.pk) + fm.finished = True + fm.save() + assert meta_model.is_finished is True + assert meta_model.is_success is False + + fm.success = True + fm.save() + assert meta_model.is_finished is True + assert meta_model.is_success is True