Skip to content

Commit

Permalink
fix: prevent enabling versioning from affecting scheduled change requ…
Browse files Browse the repository at this point in the history
…ests (#4872)
  • Loading branch information
matthewelwell authored Nov 28, 2024
1 parent 6013b84 commit c7aa30b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/features/versioning/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def _create_initial_feature_versions(environment: "Environment"):
change_request__isnull=False,
change_request__committed_at__isnull=False,
change_request__deleted_at__isnull=True,
environment=environment,
).select_related("change_request")

for feature_state in scheduled_feature_states:
ef_version = EnvironmentFeatureVersion.objects.create(
feature=feature,
Expand Down
38 changes: 38 additions & 0 deletions api/tests/unit/features/versioning/test_unit_versioning_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
get_environment_flags_queryset,
)
from features.workflows.core.models import ChangeRequest
from organisations.models import Organisation
from projects.models import Project
from segments.models import Segment
from users.models import FFAdminUser
Expand Down Expand Up @@ -233,6 +234,36 @@ def test_enable_v2_versioning_for_scheduled_changes(
version=None,
)

# and a published, scheduled feature state associated with a different project
# Note: this additional test clause is to verify an issue found in testing
# where enabling feature versioning 'stole' scheduled feature states from other
# projects.
another_organisation = Organisation.objects.create(name="another organisation")
staff_user.add_organisation(another_organisation)
another_project = Project.objects.create(
name="another project", organisation=another_organisation
)
another_environment = Environment.objects.create(
name="another environment", project=another_project
)
another_feature = Feature.objects.create(
name="another_feature", project=another_project
)
published_scheduled_cr_another_environment = ChangeRequest.objects.create(
environment=another_environment,
title="Published, scheduled change in another environment",
user=staff_user,
)
another_environment_fs = FeatureState.objects.create(
feature=another_feature,
enabled=True,
environment=another_environment,
live_from=two_hours_from_now,
change_request=published_scheduled_cr_another_environment,
version=None,
)
published_scheduled_cr_another_environment.commit(staff_user)

# When
enable_v2_versioning(environment.id)

Expand Down Expand Up @@ -260,6 +291,13 @@ def test_enable_v2_versioning_for_scheduled_changes(
== scheduled_feature_state
)

another_environment_fs.refresh_from_db()
assert another_environment_fs.environment_feature_version is None
assert (
another_environment_fs.change_request
== published_scheduled_cr_another_environment
)


def test_publish_version_change_set_sends_email_to_change_request_owner_if_conflicts_when_scheduled(
feature: Feature,
Expand Down

0 comments on commit c7aa30b

Please sign in to comment.