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(export): fixes issue exporting identity feature states with missing attributes #4987

Merged
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
16 changes: 9 additions & 7 deletions api/edge_api/identities/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ def export_edge_identity_and_overrides( # noqa: C901
override["enabled"],
)
)
featurestate_value = override["feature_state_value"]
if featurestate_value is not None:
# export feature state value
identity_override_export.append(
export_featurestate_value(featurestate_value, featurestate_uuid)
)
if mvfsv_overrides := override["multivariate_feature_state_values"]:

# We always want to create the FeatureStateValue, but if there is none in the
# dynamo object, we just create a default object with a value of null.
featurestate_value = override.get("feature_state_value")
identity_override_export.append(
export_featurestate_value(featurestate_value, featurestate_uuid)
)

if mvfsv_overrides := override.get("multivariate_feature_state_values"):
for mvfsv_override in mvfsv_overrides:
mv_feature_option_id = mvfsv_override[
"multivariate_feature_option"
Expand Down
27 changes: 26 additions & 1 deletion api/tests/unit/import_export/test_unit_import_export_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ def test_export_edge_identities(
project=project, name="mv_feature_with_deleted_option", type=MULTIVARIATE
)

# and a feature that we will override with missing attributes
feature_to_override_with_missing_attrs = Feature.objects.create(
project=project, name="feature_to_override_with_missing_attrs"
)

mv_option = multivariate_options[0]

identity_identifier = "Development_user_123456"
Expand Down Expand Up @@ -458,6 +463,19 @@ def test_export_edge_identities(
}
],
},
# An override with missing feature_state_value and multivariate_feature_state_values
# that should be handled correctly
{
"django_id": None,
"enabled": False,
"feature": {
"id": feature_to_override_with_missing_attrs.id,
"name": feature_to_override_with_missing_attrs.name,
"type": "STANDARD",
},
"featurestate_uuid": "53ab4fc5-0027-47a4-85b3-825abe2287eb",
"feature_segment": None,
},
],
"identity_traits": [
{"trait_key": "int_trait", "trait_value": 123},
Expand Down Expand Up @@ -517,7 +535,7 @@ def test_export_edge_identities(
assert bool_trait.trait_value is True

all_feature_states = identity.get_all_feature_states()
assert len(all_feature_states) == 6
assert len(all_feature_states) == 7

actual_mv_override = all_feature_states[0]
assert str(actual_mv_override.uuid) == mv_override_fs_uuid
Expand Down Expand Up @@ -549,6 +567,13 @@ def test_export_edge_identities(
)
assert override_without_mv_option.identity == identity

override_with_missing_attributes = all_feature_states[6]
assert override_with_missing_attributes.feature_state_value.value is None
assert (
override_with_missing_attributes.multivariate_feature_state_values.exists()
is False
)


@mock_s3
def test_organisation_exporter_export_to_s3(organisation):
Expand Down
Loading