diff --git a/api/features/views.py b/api/features/views.py index b276bd8f4b98..b62973aceca1 100644 --- a/api/features/views.py +++ b/api/features/views.py @@ -172,11 +172,11 @@ def get_queryset(self): identity__isnull=True, feature_segment__isnull=True, ) - feature_states = FeatureState.objects.get_live_feature_states( - self.environment, + feature_states = get_environment_flags_list( + environment=self.environment, additional_filters=q, - ).select_related("feature_state_value", "feature") - + additional_select_related_args=["feature_state_value", "feature"], + ) self._feature_states = {fs.feature_id: fs for fs in feature_states} return queryset diff --git a/api/organisations/subscriptions/metadata.py b/api/organisations/subscriptions/metadata.py index f897a3a01880..c6308892be2e 100644 --- a/api/organisations/subscriptions/metadata.py +++ b/api/organisations/subscriptions/metadata.py @@ -10,6 +10,7 @@ def __init__( api_calls: int = 0, projects: typing.Optional[int] = None, chargebee_email=None, + **kwargs, # allows for extra unknown attrs from CB json metadata ): self.seats = seats self.api_calls = api_calls diff --git a/api/tests/unit/features/test_unit_features_views.py b/api/tests/unit/features/test_unit_features_views.py index 0226d4b1a615..8874dbe91a50 100644 --- a/api/tests/unit/features/test_unit_features_views.py +++ b/api/tests/unit/features/test_unit_features_views.py @@ -2814,18 +2814,22 @@ def test_list_features_with_feature_state( project=project, ) + # This should be ignored due to versioning. feature_state1 = feature.feature_states.filter(environment=environment).first() feature_state1.enabled = True feature_state1.version = 1 feature_state1.save() - feature_state_value1 = feature_state1.feature_state_value - feature_state_value1.string_value = None - feature_state_value1.integer_value = 1945 - feature_state_value1.type = INTEGER - feature_state_value1.save() - - # This should be ignored due to versioning. + # This should be ignored due to less recent live_from compared to the next feature state + # event though it has a higher version. + FeatureState.objects.create( + feature=feature, + environment=environment, + live_from=two_hours_ago, + enabled=True, + version=101, + ) + # This should be returned feature_state_versioned = FeatureState.objects.create( feature=feature, environment=environment, @@ -2896,8 +2900,8 @@ def test_list_features_with_feature_state( assert len(response.data["results"]) == 3 results = response.data["results"] - assert results[0]["environment_feature_state"]["enabled"] is True + assert results[0]["environment_feature_state"]["id"] == feature_state_versioned.id assert results[0]["environment_feature_state"]["feature_state_value"] == 2005 assert results[0]["name"] == feature.name assert results[1]["environment_feature_state"]["enabled"] is True diff --git a/api/tests/unit/organisations/chargebee/test_unit_chargebee_cache.py b/api/tests/unit/organisations/chargebee/test_unit_chargebee_cache.py index 333a22940472..cc1f726ff7ee 100644 --- a/api/tests/unit/organisations/chargebee/test_unit_chargebee_cache.py +++ b/api/tests/unit/organisations/chargebee/test_unit_chargebee_cache.py @@ -57,6 +57,7 @@ def test_chargebee_cache(mocker, db): "seats": 10, "api_calls": 100, "projects": 10, + "some_unknown_key": 1, # should be ignored } plan_id = "plan_id" plan_items = [ @@ -69,6 +70,7 @@ def test_chargebee_cache(mocker, db): "seats": 1, "api_calls": 10, "projects": 1, + "some_unknown_key": 1, # should be ignored } addon_id = "addon_id" addon_items = [ @@ -90,8 +92,10 @@ def test_chargebee_cache(mocker, db): assert cache.plans[plan_id].seats == plan_metadata["seats"] assert cache.plans[plan_id].api_calls == plan_metadata["api_calls"] assert cache.plans[plan_id].projects == plan_metadata["projects"] + assert not hasattr(cache.plans[plan_id], "some_unknown_key") assert len(cache.addons) == 1 assert cache.addons[addon_id].seats == addon_metadata["seats"] assert cache.addons[addon_id].api_calls == addon_metadata["api_calls"] assert cache.addons[addon_id].projects == addon_metadata["projects"] + assert not hasattr(cache.addons[addon_id], "some_unknown_key")