File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from django .db import IntegrityError , OperationalError , transaction
2- from django .db .transaction import TransactionManagementError
3- from task_processor .exceptions import TaskBackoffError
4- from django .db import transaction
5- from django .core .exceptions import ObjectDoesNotExist
62from django .db .models import Prefetch , Q
3+ from django .db .transaction import TransactionManagementError
74from django .utils import timezone
85from task_processor .decorators import (
96 register_task_handler ,
107)
8+ from task_processor .exceptions import TaskBackoffError
119from task_processor .models import TaskPriority
1210
1311from audit .models import AuditLog
@@ -75,6 +73,7 @@ def delete_environment(environment_id: int) -> None:
7573 # Someone else is locking these rows, back off and retry
7674 raise TaskBackoffError ()
7775
76+
7877@register_task_handler ()
7978def clone_environment_feature_states (
8079 source_environment_id : int , clone_environment_id : int
Original file line number Diff line number Diff line change 1- from django .db import IntegrityError , OperationalError , transaction
2- from django .db .transaction import TransactionManagementError
3- from task_processor .exceptions import TaskBackoffError
4-
51import logging
62from typing import Any
73
4+ from django .db import IntegrityError , OperationalError , transaction
5+ from django .db .transaction import TransactionManagementError
86from task_processor .decorators import (
97 register_task_handler ,
108)
9+ from task_processor .exceptions import TaskBackoffError
1110
1211from environments .models import Webhook
1312from features .models import Feature , FeatureState
@@ -166,9 +165,9 @@ def delete_feature(feature_id: int) -> None:
166165 try :
167166 with transaction .atomic ():
168167 Feature .objects .get (pk = feature_id ).delete ()
169-
168+
170169 except Feature .DoesNotExist :
171170 pass
172-
171+
173172 except (OperationalError , IntegrityError , TransactionManagementError ):
174173 raise TaskBackoffError ()
Original file line number Diff line number Diff line change 1- from pytest_mock import MockerFixture
21from django .db import OperationalError
2+ from pytest_mock import MockerFixture
33from task_processor .exceptions import TaskBackoffError
4- from environments .models import Environment
5- from environments .tasks import delete_environment
4+
65from audit .models import AuditLog
76from environments .models import Environment
87from environments .tasks import (
8+ delete_environment ,
99 delete_environment_from_dynamo ,
1010 process_environment_update ,
1111 rebuild_environment_document ,
@@ -116,6 +116,8 @@ def test_delete_environment__calls_internal_methods_correctly(
116116 mocked_identity_wrapper .delete_all_identities .assert_called_once_with (
117117 environment_api_key
118118 )
119+
120+
119121@pytest .mark .django_db
120122def test_delete_environment__environment_does_not_exist__succeeds_silently (
121123 mocker : MockerFixture ,
Original file line number Diff line number Diff line change 11import pytest
2+ from django .db import OperationalError
23from pytest_lazyfixture import lazy_fixture # type: ignore[import-untyped]
34from pytest_mock import MockerFixture
4- from unittest import mock
5- from django .db import OperationalError
65from task_processor .exceptions import TaskBackoffError
7- from features . tasks import delete_feature
6+
87from api_keys .models import MasterAPIKey
98from environments .models import Environment
109from features .models import Feature , FeatureState
11- from features .tasks import trigger_feature_state_change_webhooks
10+ from features .tasks import delete_feature , trigger_feature_state_change_webhooks
1211from organisations .models import Organisation
1312from projects .models import Project
1413from users .models import FFAdminUser
@@ -166,6 +165,7 @@ def test_trigger_feature_state_change_webhooks_for_deleted_flag_uses_fs_instance
166165 assert data ["previous_state" ]["feature" ]["id" ] == feature_state .feature .id
167166 assert event_type == WebhookEventType .FLAG_DELETED .value
168167
168+
169169@pytest .mark .django_db
170170def test_delete_feature__feature_does_not_exist__succeeds_silently (
171171 mocker : MockerFixture ,
You can’t perform that action at this time.
0 commit comments