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(5044): handle deleted feature state #5045

Merged
merged 1 commit into from
Jan 28, 2025
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
8 changes: 6 additions & 2 deletions api/features/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,13 @@ def copy_from(self, source_feature_state_value: "FeatureStateValue"):

def get_skip_create_audit_log(self) -> bool:
try:
if self.feature_state.deleted_at:
return True

return self.feature_state.get_skip_create_audit_log()
except ObjectDoesNotExist:
return False

except FeatureState.DoesNotExist:
return True

def get_update_log_message(self, history_instance) -> typing.Optional[str]:
fs = self.feature_state
Expand Down
50 changes: 47 additions & 3 deletions api/tests/unit/features/test_unit_features_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,9 @@ def test_feature_state_value_get_skip_create_audit_log_if_environment_feature_ve
assert feature_state.feature_state_value.get_skip_create_audit_log() is True


def test_feature_state_value__get_skip_create_audit_log_for_deleted_feature_state(
def test_feature_state_value__get_skip_create_audit_log_for_feature_segment_delete(
feature: Feature, feature_segment: FeatureSegment, environment: Environment
):
) -> None:
# Give
feature_state = FeatureState.objects.create(
feature=feature, feature_segment=feature_segment, environment=environment
Expand All @@ -763,7 +763,51 @@ def test_feature_state_value__get_skip_create_audit_log_for_deleted_feature_stat
id=feature_state_value.id, history_type="-"
).first()

assert fsv_history_instance.instance.get_skip_create_audit_log() is False
assert fsv_history_instance.instance.get_skip_create_audit_log() is True


def test_feature_state_value__get_skip_create_audit_log_for_identity_delete(
feature: Feature,
environment: Environment,
identity: Identity,
) -> None:
# Give
feature_state = FeatureState.objects.create(
feature=feature, identity=identity, environment=environment
)
feature_state_value = feature_state.feature_state_value

# When
# Delete identity to cascade delete feature state
# instead of soft delete
identity.delete()

# Then
fsv_history_instance = FeatureStateValue.history.filter(
id=feature_state_value.id, history_type="-"
).first()

assert fsv_history_instance.instance.get_skip_create_audit_log() is True


def test_feature_state_value__get_skip_create_audit_log_for_feature_delete(
feature: Feature,
environment: Environment,
identity: Identity,
) -> None:
# Give
feature_state = FeatureState.objects.get(feature=feature, environment=environment)
feature_state_value = feature_state.feature_state_value

# When
feature.delete()

# Then
fsv_history_instance = FeatureStateValue.history.filter(
id=feature_state_value.id, history_type="-"
).first()

assert fsv_history_instance.instance.get_skip_create_audit_log() is True


@pytest.mark.parametrize(
Expand Down
Loading