Skip to content

Commit fe840c5

Browse files
fix(multivariate): persist variant key in DynamoDB environment document (#7915)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 772b9cb commit fe840c5

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

api/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ dependencies = [
7474
"hubspot-api-client>=12.0.0,<13.0.0",
7575
"djangorestframework-dataclasses>=1.3.1,<2.0.0",
7676
"pyotp>=2.9.0,<3.0.0",
77-
"flagsmith-common[common-core,flagsmith-schemas,task-processor]>=3.9.1,<4",
77+
"flagsmith-common[common-core,flagsmith-schemas,task-processor]>=3.10.1,<4",
7878
"django-stubs>=5.1.3,<6.0.0",
7979
"tzdata>=2024.1,<2025.0.0",
8080
"djangorestframework-simplejwt>=5.5.1,<6.0.0",

api/tests/unit/util/mappers/test_unit_mappers_dynamodb.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from environments.identities.models import Identity
1717
from environments.identities.traits.models import Trait
1818
from environments.models import Environment, EnvironmentAPIKey
19-
from features.models import FeatureState
19+
from features.models import Feature, FeatureState
2020

2121

2222
def test_map_environment_to_environment_document__valid_environment__returns_expected_document(
@@ -263,6 +263,32 @@ def test_map_environment_to_compressed_environment_document__valid_environment__
263263
)
264264

265265

266+
def test_map_environment_to_compressed_environment_document__mv_option_with_key__key_preserved(
267+
environment: "Environment",
268+
multivariate_feature: "Feature",
269+
) -> None:
270+
# Given
271+
mv_option = multivariate_feature.multivariate_options.first()
272+
assert mv_option is not None
273+
mv_option.key = "control"
274+
mv_option.save()
275+
276+
# When
277+
result = dynamodb.map_environment_to_compressed_environment_document(environment)
278+
279+
# Then
280+
feature_states = json.loads(
281+
gzip.decompress(result.document["feature_states"]).decode("utf-8")
282+
)
283+
mv_options = [
284+
mv_value["multivariate_feature_option"]
285+
for feature_state in feature_states
286+
for mv_value in feature_state["multivariate_feature_state_values"]
287+
]
288+
keyed_option = next(option for option in mv_options if option["id"] == mv_option.id)
289+
assert keyed_option["key"] == "control"
290+
291+
266292
def test_map_environment_to_compressed_environment_v2_document__valid_environment__returns_compressed_fields(
267293
environment: "Environment",
268294
feature_state: "FeatureState",

api/uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)