Skip to content

Commit

Permalink
fix(organisation): allow Organisation delete when committed change re…
Browse files Browse the repository at this point in the history
…quest present (#5101)
  • Loading branch information
matthewelwell authored Feb 13, 2025
1 parent a116f2c commit 2a13d81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion api/features/workflows/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ def prevent_change_request_delete_if_committed(self) -> None:
# deleted but, since this can have unexpected effects on published
# feature states, we also want to prevent it at the ORM level.
if self.committed_at and not (
self.environment.deleted_at
(self.environment and self.environment.deleted_at)
or (self.project and self.project.deleted_at)
or (self.live_from and self.live_from > timezone.now())
):
raise ChangeRequestDeletionError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ChangeRequestApproval,
ChangeRequestGroupAssignment,
)
from organisations.models import Organisation
from projects.models import Project
from segments.models import Condition, Segment, SegmentRule
from users.models import FFAdminUser
Expand Down Expand Up @@ -1003,3 +1004,22 @@ def test_url_via_project(project_change_request: ChangeRequest) -> None:
expected_url = get_current_site_url()
expected_url += f"/project/{project_id}/change-requests/{project_change_request.id}"
assert url == expected_url


def test_delete_organisation_with_committed_change_request(
organisation: Organisation,
feature: Feature,
change_request_no_required_approvals: ChangeRequest,
admin_user: FFAdminUser,
) -> None:
"""
Specific test to cover https://github.com/Flagsmith/flagsmith/issues/5097
"""
# Given
change_request_no_required_approvals.commit(admin_user)

# When
organisation.delete()

# Then
assert organisation.deleted_at is not None

0 comments on commit 2a13d81

Please sign in to comment.