Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent enabling versioning from affecting scheduled change requests #4872

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading