MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / validate_name

Method validate_name

api/features/serializers.py:357–385  ·  view source on GitHub ↗
(self, name: str)

Source from the content-addressed store, hash-verified

355 return group_owners
356
357 def validate_name(self, name: str): # type: ignore[no-untyped-def]
358 view = self.context["view"]
359
360 project = self.context["project"]
361 feature_name_regex = project.feature_name_regex
362
363 if not project.is_feature_name_valid(name):
364 raise serializers.ValidationError(
365 f"Feature name must match regex: {feature_name_regex}"
366 )
367
368 unique_filters = {
369 "project__id": view.kwargs.get("project_pk"),
370 "name__iexact": name,
371 }
372 existing_feature_queryset = Feature.objects.filter(**unique_filters)
373 if self.instance:
374 existing_feature_queryset = existing_feature_queryset.exclude(
375 id=self.instance.id # type: ignore[union-attr]
376 )
377
378 if existing_feature_queryset.exists():
379 raise serializers.ValidationError(
380 "Feature with that name already exists for this "
381 "project. Note that feature names are case "
382 "insensitive."
383 )
384
385 return name
386
387 def validate(self, attrs: dict[str, Any]) -> dict[str, Any]:
388 view = self.context["view"]

Callers

nothing calls this directly

Calls 3

is_feature_name_validMethod · 0.80
existsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected