From bb3a6d6ef25a345683be09b022e8617b318bcdb6 Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Tue, 11 Feb 2025 09:47:20 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=AF=BC=E5=87=BA=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E5=89=8D=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=AD=90=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E6=95=B0=E6=8D=AE=E7=89=88=E6=9C=AC=E7=9A=84=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=20#7694?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/template_base/models.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gcloud/template_base/models.py b/gcloud/template_base/models.py index 008e96f818..a0764202a1 100644 --- a/gcloud/template_base/models.py +++ b/gcloud/template_base/models.py @@ -96,6 +96,14 @@ def export_templates(self, template_id_list, **kwargs): raise FlowExportError(str(e)) all_template_ids = set(pipeline_temp_data["template"].keys()) + tmpl_and_pipeline_id = self.filter(pipeline_template_id__in=all_template_ids).values( + "id", "pipeline_template_id" + ) + expired_subprocess = self.check_templates_subprocess_expired(tmpl_and_pipeline_id, check_latest=True) + if expired_subprocess: + raise FlowExportError( + f"template {expired_subprocess} has expired subprocess, please update it before exporting." + ) additional_template_id = all_template_ids - set(pipeline_template_id_list) subprocess_temp_list = list( self.filter(pipeline_template_id__in=additional_template_id).select_related("pipeline_template").values() @@ -276,10 +284,12 @@ def _perform_import(self, template_data, check_info, override, defaults_getter, "code": err_code.SUCCESS.code, } - def check_templates_subprocess_expired(self, tmpl_and_pipeline_id): + def check_templates_subprocess_expired(self, tmpl_and_pipeline_id, check_latest=False): # fetch all template relationship in template_ids pipeline_tmpl_ids = [item["pipeline_template_id"] for item in tmpl_and_pipeline_id] subproc_infos = TemplateRelationship.objects.filter(ancestor_template_id__in=pipeline_tmpl_ids) + if not check_latest: + subproc_infos = subproc_infos.filter(always_use_latest=0) # get all subprocess reference template's version subproc_templ = [info.descendant_template_id for info in subproc_infos] @@ -292,7 +302,7 @@ def check_templates_subprocess_expired(self, tmpl_and_pipeline_id): # compare subproc_expired_templ = set() for info in subproc_infos: - if info.descendant_template_id not in tmpl_version_map or info.always_use_latest: + if info.descendant_template_id not in tmpl_version_map: continue if info.version != tmpl_version_map.get(info.descendant_template_id): subproc_expired_templ.add(info.ancestor_template_id) From f029db13bb9f097841f1a7addff3039dc13a6ff4 Mon Sep 17 00:00:00 2001 From: guohelu <19503896967@163.com> Date: Tue, 11 Feb 2025 11:32:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E6=B5=8B=E8=AF=95=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D=20#7694?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gcloud/template_base/models.py | 6 +++--- .../test_check_templates_subprocess_expired.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gcloud/template_base/models.py b/gcloud/template_base/models.py index a0764202a1..c06eb54baa 100644 --- a/gcloud/template_base/models.py +++ b/gcloud/template_base/models.py @@ -288,11 +288,11 @@ def check_templates_subprocess_expired(self, tmpl_and_pipeline_id, check_latest= # fetch all template relationship in template_ids pipeline_tmpl_ids = [item["pipeline_template_id"] for item in tmpl_and_pipeline_id] subproc_infos = TemplateRelationship.objects.filter(ancestor_template_id__in=pipeline_tmpl_ids) - if not check_latest: - subproc_infos = subproc_infos.filter(always_use_latest=0) # get all subprocess reference template's version - subproc_templ = [info.descendant_template_id for info in subproc_infos] + subproc_templ = [ + info.descendant_template_id for info in subproc_infos if check_latest or not info.always_use_latest + ] tmpl_versions = TemplateCurrentVersion.objects.filter(template_id__in=subproc_templ) # comparison data prepare diff --git a/gcloud/tests/template_base/models/base_template_manager/test_check_templates_subprocess_expired.py b/gcloud/tests/template_base/models/base_template_manager/test_check_templates_subprocess_expired.py index 198f070d69..03dedf079c 100644 --- a/gcloud/tests/template_base/models/base_template_manager/test_check_templates_subprocess_expired.py +++ b/gcloud/tests/template_base/models/base_template_manager/test_check_templates_subprocess_expired.py @@ -81,7 +81,7 @@ def test_normal(self): TemplateRelationship.objects.filter = MagicMock(return_value=[r1, r2, r3, r4, r5]) TemplateCurrentVersion = MagicMock() - TemplateCurrentVersion.objects.filter = MagicMock(return_value=[v1, v2, v3, v4, v5]) + TemplateCurrentVersion.objects.filter = MagicMock(return_value=[v2, v3, v5]) with patch(TEMPLATE_BASE_MODELS_TEMPLATE_RELATIONSHIP, TemplateRelationship): with patch(TEMPLATE_BASE_MODELS_TEMPLATE_CURRENT_VERSION, TemplateCurrentVersion):