Skip to content

Commit

Permalink
fix(versioning): use transaction.atomic to prevent corrupt versions b…
Browse files Browse the repository at this point in the history
…eing created (#4617)
  • Loading branch information
matthewelwell committed Sep 11, 2024
1 parent f8a048e commit 7ac05cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/features/versioning/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing

from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
from rest_framework import serializers

from api_keys.user import APIKeyUser
Expand Down Expand Up @@ -140,6 +141,7 @@ class Meta(EnvironmentFeatureVersionSerializer.Meta):
"publish_immediately",
)

@transaction.atomic
def create(
self, validated_data: dict[str, typing.Any]
) -> EnvironmentFeatureVersion:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ def test_publish_version_change_set_raises_error_when_segment_override_does_not_
f"An unresolvable conflict occurred: segment override does not exist for segment '{segment.name}'."
)

# and we should still only have a single version for the feature
assert (
EnvironmentFeatureVersion.objects.filter(
environment=environment_v2_versioning, feature=feature
).count()
== 1
)


def test_publish_version_change_set_raises_error_when_serializer_not_valid(
change_request: ChangeRequest,
Expand Down

0 comments on commit 7ac05cd

Please sign in to comment.