def save(self, **kwargs: typing.Any) -> FeatureSegment:
        """
        Note that this method is marked as atomic since a lot of additional validation is
        performed in the call to super. If that fails, we want to roll the changes made by
        `collision.to` back.
        """

        priority: int | None = self.validated_data.get("priority", None)

        if kwargs["environment"].use_v2_feature_versioning:  # pragma: no cover
            assert kwargs["environment_feature_version"] is not None, (
                "Must provide environment_feature_version for environment using v2 versioning"
            )

        if priority is not None:
            collision_qs = FeatureSegment.objects.filter(
                environment=kwargs["environment"],
                feature=kwargs["feature"],
                environment_feature_version=kwargs.get("environment_feature_version"),
                priority=priority,
            )
            if self.instance is not None:
                assert isinstance(self.instance, FeatureSegment)
                collision_qs = collision_qs.exclude(id=self.instance.id)
            collision = collision_qs.first()
            if collision:
                # Since there is no unique clause on the priority field, if a priority
                # is set, it will just save the feature segment and not move others
                # down. This ensures that the incoming priority space is 'free'.
                collision.to(priority + 1)

        return super().save(**kwargs)  # type: ignore[return-value]

        Note that this method is marked as atomic since a lot of additional validation is
        performed in the call to super. If that fails, we want to roll the changes made by
        `collision.to` back.
        
api/features/feature_segments/serializers.py