Skip to content

Commit eda5fb1

Browse files
committed
fix: remove unrelated test and optimize query in _validate_owner_removal
- Remove test_update_feature_state__null_environment__returns_400 (unrelated to this PR, should be a separate PR if fixing a bug) - Only query existing owners when the corresponding ID set is non-empty to avoid unnecessary DB queries
1 parent 2b12acf commit eda5fb1

2 files changed

Lines changed: 14 additions & 33 deletions

File tree

api/features/views.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -487,16 +487,21 @@ def _validate_owner_removal(
487487
if not feature.project.enforce_feature_owners:
488488
return
489489

490-
existing_owner_ids = set(
491-
feature.owners.values_list("id", flat=True)
492-
)
493-
existing_group_owner_ids = set(
494-
feature.group_owners.values_list("id", flat=True)
490+
actual_owners_to_remove = (
491+
len(
492+
owner_ids
493+
& set(feature.owners.values_list("id", flat=True))
494+
)
495+
if owner_ids
496+
else 0
495497
)
496-
497-
actual_owners_to_remove = len(owner_ids & existing_owner_ids)
498-
actual_group_owners_to_remove = len(
499-
group_owner_ids & existing_group_owner_ids
498+
actual_group_owners_to_remove = (
499+
len(
500+
group_owner_ids
501+
& set(feature.group_owners.values_list("id", flat=True))
502+
)
503+
if group_owner_ids
504+
else 0
500505
)
501506

502507
remaining = (

api/tests/unit/features/test_unit_features_views.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,30 +3246,6 @@ def test_update_feature_state__change_feature__returns_400(
32463246
)
32473247

32483248

3249-
def test_update_feature_state__null_environment__returns_400(
3250-
admin_client_new: APIClient,
3251-
environment: Environment,
3252-
feature: Feature,
3253-
feature_state: FeatureState,
3254-
) -> None:
3255-
# Given
3256-
url = reverse("api-v1:features:featurestates-detail", args=[feature_state.id])
3257-
data = {
3258-
"enabled": True,
3259-
"environment": None,
3260-
"feature": feature.id,
3261-
}
3262-
3263-
# When
3264-
response = admin_client_new.put(
3265-
url, data=json.dumps(data), content_type="application/json"
3266-
)
3267-
3268-
# Then
3269-
assert response.status_code == status.HTTP_400_BAD_REQUEST
3270-
assert "environment" in response.json()
3271-
3272-
32733249
@pytest.mark.parametrize(
32743250
"client",
32753251
[lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")],

0 commit comments

Comments
 (0)