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(feature-service/get_edge_override): handle deleted features #3368

Merged
merged 4 commits into from
Feb 2, 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
8 changes: 5 additions & 3 deletions api/features/features_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ def get_edge_overrides_data(
if feature_state.feature_segment_id:
env_feature_overrides_data.num_segment_overrides += 1
for identity_override in get_overrides_data_future.result():
all_overrides_data[
identity_override.feature_state.feature.id
].add_identity_override()
# Only override features that exists in core
if identity_override.feature_state.feature.id in all_overrides_data:
all_overrides_data[
identity_override.feature_state.feature.id
].add_identity_override()

return all_overrides_data
36 changes: 36 additions & 0 deletions api/tests/unit/features/test_unit_features_features_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,39 @@ def test_feature_get_edge_overrides_data(
overrides_data[distinct_segment_featurestate.feature.id].num_segment_overrides
== 1
)


@pytest.mark.django_db(transaction=True)
def test_get_edge_overrides_data_skips_deleted_features(
feature: Feature,
environment: "Environment",
identity: Identity,
identity_featurestate: FeatureState,
distinct_identity_featurestate: FeatureState,
dynamodb_identity_wrapper: "DynamoIdentityWrapper",
dynamodb_wrapper_v2: "DynamoEnvironmentV2Wrapper",
):
# Given
# replicate identity to Edge
edge_identity = EdgeIdentity(map_identity_to_engine(identity, with_overrides=False))
# Create identity override for two different features
edge_identity.add_feature_override(
map_feature_state_to_engine(identity_featurestate),
)
edge_identity.add_feature_override(
map_feature_state_to_engine(distinct_identity_featurestate),
)
Comment on lines +280 to +285
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can discuss this on the standup but I'm a little unsure on the details here. Are these overrides for 2 different features?

It's not obvious to me from the test why we're still left with one edge identity override.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's for a different feature

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some comments would probably help here.

# Let's add 2 overrides for 2 separate features for the edge identity
edge_identity.add_feature_override(
    ...

# and delete one of the features
feature.delete()

edge_identity.save()

# Now, delete one of the feature
feature.delete()

# When
overrides_data = get_edge_overrides_data(environment)

# Then - we only have one identity override(for the feature that still exists)
assert len(overrides_data) == 1
assert (
overrides_data[distinct_identity_featurestate.feature.id].num_identity_overrides
== 1
)
Loading