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: cannot create new segments due to segment validation #4886

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
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
39 changes: 9 additions & 30 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ hubspot-api-client = "^8.2.1"
djangorestframework-dataclasses = "^1.3.1"
pyotp = "^2.9.0"
flagsmith-task-processor = { git = "https://github.com/Flagsmith/flagsmith-task-processor", tag = "v1.0.2" }
flagsmith-common = { git = "https://github.com/Flagsmith/flagsmith-common", tag = "v1.4.0" }
flagsmith-common = { git = "https://github.com/Flagsmith/flagsmith-common", tag = "v1.4.2" }
tzdata = "^2024.1"
djangorestframework-simplejwt = "^5.3.1"

Expand All @@ -196,7 +196,7 @@ flagsmith-ldap = { git = "https://github.com/flagsmith/flagsmith-ldap", tag = "v
optional = true

[tool.poetry.group.workflows.dependencies]
workflows-logic = { git = "https://github.com/flagsmith/flagsmith-workflows", tag = "v2.7.2" }
workflows-logic = { git = "https://github.com/flagsmith/flagsmith-workflows", tag = "v2.7.4" }

[tool.poetry.group.dev.dependencies]
django-test-migrations = "~1.2.0"
Expand Down
38 changes: 38 additions & 0 deletions api/tests/unit/segments/test_unit_segments_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,44 @@ def test_create_segments_reaching_max_limit(project, client, settings):
assert project.segments.count() == 1


def test_segments_limit_ignores_old_segment_versions(
project: Project,
segment: Segment,
staff_client: APIClient,
with_project_permissions: WithProjectPermissionsCallable,
) -> None:
# Given
with_project_permissions([MANAGE_SEGMENTS])

# let's reduce the max segments allowed to 2
project.max_segments_allowed = 2
project.save()

# and create some older versions for the segment fixture
segment.deep_clone()
assert Segment.objects.filter(version_of_id=segment.id).count() == 3
assert Segment.live_objects.count() == 1

url = reverse("api-v1:projects:project-segments-list", args=[project.id])
data = {
"name": "New segment name",
"project": project.id,
"rules": [
{
"type": "ALL",
"rules": [],
"conditions": [{"operator": EQUAL, "property": "test-property"}],
}
],
}

# When
res = staff_client.post(url, data=json.dumps(data), content_type="application/json")

# Then
assert res.status_code == status.HTTP_201_CREATED


@pytest.mark.parametrize(
"client",
[lazy_fixture("admin_master_api_key_client"), lazy_fixture("admin_client")],
Expand Down
Loading