Flagsmith / Flagsmith/flagsmith

Fix segment limit counting hidden segments

Open
#8,369 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6.6k
Forks
567
Avg merge
1d 13h
Merged PRs (30d)
121

Description

### How are you running Flagsmith

- [x] SaaS at flagsmith.com

### Describe the bug

The project segment limit counts feature-specific and system segments, which are hidden from the segments list. A project can therefore hit `max_segments_allowed` (and show a full Project Usage bar) with far fewer segments visible than the limit.

- The segments list (`SegmentViewSet.get_queryset`) excludes system segments always, and feature-specific ones by default (`include_feature_specific=false`).
- The usage count and enforcement (`Project.live_segment_count()`, `_validate_project_segment_limit`) count every canonical segment, feature-specific and system included.

Feature-specific overrides already have their own limit (`max_segment_overrides_allowed`), so counting them against `max_segments_allowed` double-counts them.

### Steps To Reproduce

1. In a project, add enough feature-specific overrides (and/or experiments) that the total canonical segment count approaches `max_segments_allowed`.
2. Project Settings → Usage: the Segments bar reads near or at the limit (e.g. 499/500).
3. Open the Segments list: far fewer segments are shown, since feature-specific are hidden by default.
4. Try to create a new segment: blocked with "The project has reached the maximum allowed segments limit", despite the visible count being well under the limit.

### Expected behavior

The segment limit and the Project Usage count reflect the segments shown in the list (exclude feature-specific and system segments), so the usage matches what a user can see and manage. Feature-specific overrides remain bounded by `max_segment_overrides_allowed`.

### Screenshots

_N/A_

Contributor guide

Open the contributing guide

Research direction

Start by tracing Project.live_segment_count() and _validate_project_segment_limit, then compare their canonical-segment query with SegmentViewSet.get_queryset. Reproduce the Project Settings → Usage count and segment-creation limit using feature-specific and system segments; done means hidden segments are excluded, visible usage matches the list, and feature-specific overrides remain governed by max_segment_overrides_allowed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.