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

Class FeatureStateSerializerBasic

api/features/serializers.py:666–770  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

664
665
666class FeatureStateSerializerBasic(WritableNestedModelSerializer):
667 feature_state_value = serializers.SerializerMethodField()
668 multivariate_feature_state_values = MultivariateFeatureStateValueSerializer(
669 many=True, required=False
670 )
671 identifier = serializers.CharField(
672 required=False,
673 help_text="Can be passed as an alternative to `identity`",
674 )
675
676 class Meta:
677 model = FeatureState
678 fields = "__all__"
679 read_only_fields = ("version", "created_at", "updated_at", "status")
680
681 @extend_schema_field(
682 {
683 "type": [
684 "string",
685 "integer",
686 "number",
687 "boolean",
688 "null",
689 ],
690 }
691 )
692 def get_feature_state_value(self, obj): # type: ignore[no-untyped-def]
693 return obj.get_feature_state_value(identity=self.context.get("identity"))
694
695 def save(self, **kwargs): # type: ignore[no-untyped-def]
696 try:
697 response = super().save(**kwargs) # type: ignore[no-untyped-call]
698
699 feature_state = self.instance
700 if (
701 not feature_state.identity_id # type: ignore[union-attr]
702 and feature_state.feature.external_resources.exists() # type: ignore[union-attr]
703 and feature_state.environment.project.github_project.exists() # type: ignore[union-attr]
704 and feature_state.environment.project.organisation.github_config.exists() # type: ignore[union-attr]
705 ):
706 call_github_task(
707 organisation_id=feature_state.feature.project.organisation_id, # type: ignore[union-attr]
708 type=GitHubEventType.FLAG_UPDATED.value,
709 feature=feature_state.feature, # type: ignore[union-attr]
710 segment_name=None,
711 url=None,
712 feature_states=[feature_state],
713 )
714
715 if isinstance(feature_state, FeatureState):
716 post_gitlab_state_change_comment_for_feature_state(feature_state)
717
718 return response
719
720 except django.core.exceptions.ValidationError as e:
721 raise serializers.ValidationError(str(e))
722
723 def validate_feature(self, feature): # type: ignore[no-untyped-def]

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…