Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 导出流程前添加对子流程数据版本的检查 #7694 #7697

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions gcloud/template_base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -276,13 +284,15 @@ 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)

# 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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading