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: Avoid recursion during identity features validation #201

Merged
merged 1 commit into from
Jan 17, 2024
Merged
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
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
Loading