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: Raise if environment_feature_version is None #5028

Merged
merged 7 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,14 +471,14 @@ def _with_project_permissions(


@pytest.fixture()
def environment_v2_versioning(environment):
def environment_v2_versioning(environment: Environment):
zachaysan marked this conversation as resolved.
Show resolved Hide resolved
enable_v2_versioning(environment.id)
environment.refresh_from_db()
return environment


@pytest.fixture()
def identity(environment):
def identity(environment: Environment):
zachaysan marked this conversation as resolved.
Show resolved Hide resolved
return Identity.objects.create(identifier="test_identity", environment=environment)


Expand Down
8 changes: 8 additions & 0 deletions api/features/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,14 @@ def __gt__(self, other: "FeatureState") -> bool: # noqa: C901

if self.type == other.type:
if self.environment.use_v2_feature_versioning:
if (
self.environment_feature_version is None
or other.environment_feature_version is None
):
raise ValueError(
"Cannot compare feature states as they are missing environment_feature_version."
)

return (
self.environment_feature_version > other.environment_feature_version
)
Expand Down
30 changes: 30 additions & 0 deletions api/tests/unit/features/test_unit_features_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,36 @@ def test_feature_state_gt_operator_order(
assert segment_2_state > default_env_state


def test_feature_state_gt_operator_order_when_environment_feature_version_is_none(
identity: Identity,
feature: Feature,
feature_state: FeatureState,
environment: Environment,
environment_v2_versioning: Environment,
mocker: MockerFixture,
) -> None:
# Given
feature_state2 = FeatureState.objects.create(
identity=identity, feature=feature, environment=environment
)
mocker.patch.object(
FeatureState,
"type",
new_callable=mocker.PropertyMock,
return_value="ENVIRONMENT",
)

# When
with pytest.raises(ValueError) as exception:
assert feature_state > feature_state2

# Then
assert (
exception.value.args[0]
== "Cannot compare feature states as they are missing environment_feature_version."
)


def test_feature_state_gt_operator_throws_value_error_if_different_environments(
project: Project,
environment: Environment,
Expand Down
Loading