Skip to content

Commit

Permalink
fix: Avoid recursion during identity features validation (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 authored Jan 17, 2024
1 parent 2f09b52 commit 4a257e1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions flag_engine/identities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
class IdentityFeaturesList(BaseCollectionModel[FeatureStateModel]): # type: ignore[misc,no-any-unimported]
@staticmethod
def _ensure_unique_feature_ids(
value: typing.MutableSequence[FeatureStateModel],
) -> typing.MutableSequence[FeatureStateModel]:
value: typing.Sequence[FeatureStateModel],
) -> None:
for i, feature_state in enumerate(value, start=1):
if feature_state.feature.id in [
feature_state.feature.id for feature_state in value[i:]
]:
raise DuplicateFeatureState(
f"Feature state for feature id={feature_state.feature.id} already exists"
)
return value

unique_feature_ids_validator = model_validator(mode="after")(
_ensure_unique_feature_ids
)
@model_validator(mode="after")
def ensure_unique_feature_ids(self) -> "IdentityFeaturesList":
self._ensure_unique_feature_ids(self.root)
return self

def append(self, feature_state: "FeatureStateModel") -> None:
self._ensure_unique_feature_ids([*self, feature_state])
Expand Down

0 comments on commit 4a257e1

Please sign in to comment.