Skip to content

Commit

Permalink
fix(views/features): use get_environment_flags_list (#4511)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Aug 19, 2024
1 parent 1e3888a commit 7034fa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
8 changes: 4 additions & 4 deletions api/features/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions api/tests/unit/features/test_unit_features_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7034fa4

Please sign in to comment.