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

fix: 测试bug修改 --story=121224121 #7670

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion gcloud/contrib/template_market/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ class TemplateSceneViewSet(viewsets.ViewSet):
market_client = MarketAPIClient

def _build_template_data(self, serializer, **kwargs):
template_ids = serializer.validated_data["templates"]

templates = TaskTemplate.objects.filter(
id__in=serializer.validated_data["templates"],
id__in=template_ids,
project_id=serializer.validated_data["project_code"],
is_deleted=False,
)
if templates.count() != len(template_ids):
missing_ids = set(template_ids) - {template.id for template in templates}
raise ValueError(f"Templates with IDs {missing_ids} are missing or deleted.")

template_info = [{"id": template.id, "name": template.name} for template in templates]
serializer.validated_data["templates"] = template_info
data = {"source_system": settings.APP_CODE, **serializer.validated_data}
Expand Down
12 changes: 11 additions & 1 deletion gcloud/core/apis/drf/serilaziers/periodic_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def inspect_cron(self, cron):


class CreatePeriodicTaskSerializer(CronFieldSerializer, serializers.ModelSerializer):
id = serializers.IntegerField(required=False)
project = serializers.IntegerField(write_only=True)
template_source = serializers.CharField(required=False, default=PROJECT)
pipeline_tree = ReadWriteSerializerMethodField()
Expand Down Expand Up @@ -219,7 +220,16 @@ def validate(self, attrs):

class Meta:
model = PeriodicTask
fields = ["project", "cron", "name", "template_id", "pipeline_tree", "template_source", "template_scheme_ids"]
fields = [
"id",
"project",
"cron",
"name",
"template_id",
"pipeline_tree",
"template_source",
"template_scheme_ids",
]


class PatchUpdatePeriodicTaskSerializer(CronFieldSerializer, serializers.Serializer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from gcloud.iam_auth import res_factory
from gcloud.iam_auth.intercept import ViewInterceptor
from gcloud.contrib.template_market.models import TemplateSharedRecord
from gcloud.tasktmpl3.models import TaskTemplate

iam = get_iam_client()

Expand All @@ -32,13 +33,22 @@ def process(self, request, *args, **kwargs):
template_ids = data.get("template_ids")
subject = Subject("user", request.user.username)

existing_templates = TaskTemplate.objects.filter(
project_id=request.project.id, id__in=template_ids
guohelu marked this conversation as resolved.
Show resolved Hide resolved
).values_list("id", flat=True)
missing_template_ids = set(template_ids) - set(existing_templates)
if missing_template_ids:
error_message = f"The following templates already not exist {missing_template_ids}"
logging.error(error_message)
raise ValueError(error_message)

existing_records = TemplateSharedRecord.objects.filter(
project_id=request.project.id, template_id__in=template_ids
).values_list("template_id", flat=True)

missing_template_ids = set(template_ids) - set(existing_records)
if missing_template_ids:
error_message = f"The following templates are not shared {missing_template_ids}"
missing_template_records_ids = set(template_ids) - set(existing_records)
if missing_template_records_ids:
error_message = f"The following templates are not shared {missing_template_records_ids}"
logging.error(error_message)
raise ValueError(error_message)

Expand Down
Loading