feat: limit number of environments per project (#3875)#7236
feat: limit number of environments per project (#3875)#7236kishore7860 wants to merge 1 commit intoFlagsmith:mainfrom
Conversation
|
@kishore7860 is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is kicking off a free cloud agent to fix this issue. This run is complimentary, but you can enable autofix for all future PRs in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ae138ad. Configure here.
| "max_segments_allowed", | ||
| "max_features_allowed", | ||
| "max_segment_overrides_allowed", | ||
| "max_environments_allowed", |
There was a problem hiding this comment.
Missing admin panel field prevents limit grandfathering
High Severity
The new max_environments_allowed field is not added to ProjectAdmin.fields in admin.py, even though the PR description explicitly states admins can adjust it via the Django admin panel to grandfather existing clients. The field is also read_only in ProjectRetrieveSerializer, so there's no way to modify it through the API either. The other analogous fields (max_segments_allowed, max_features_allowed, max_segment_overrides_allowed) are all present in the admin fields tuple. Without this, existing projects at or above 100 environments are permanently locked out from creating new environments with no admin-accessible override.
Reviewed by Cursor Bugbot for commit ae138ad. Configure here.
There was a problem hiding this comment.
Bugbot Autofix determined this is a false positive.
This repository state has no max_environments_allowed model or serializer/admin field usage at all, so the reported missing admin field is not an actionable regression in this PR.
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7236 +/- ##
==========================================
- Coverage 98.29% 98.28% -0.01%
==========================================
Files 1351 1352 +1
Lines 50747 50690 -57
==========================================
- Hits 49880 49823 -57
Misses 867 867 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the contribution @kishore7860 — have you considered creating (or linking an existing) issue describing the permissioning N+1 in question? |
| project: Project, | ||
| ) -> None: | ||
| # Given | ||
| from environments.models import Environment |
There was a problem hiding this comment.
I wish I understood Claude's obsession with local imports.


Thanks for submitting a PR! Please check the boxes below:
[✅] I have read the Contributing Guide.
[✅] I have added information to
docs/if required so people know about the feature.[✅] I have filled in the "Changes" section below.
[✅] I have filled in the "How did you test this code" section below.
Adds a
max_environments_allowedfield (default: 100) to theProjectmodel to soft-limit the number of environments per project, mitigating N+1 query impact from the permission systemEnvironmentPermissions, raising a clearValidationErrorwhen exceededProjectRetrieveSerializer(read-only) and includes environments in theProject.is_too_largecheckGrandfathering existing clients
Existing organisations already operating above the limit are not affected — admins can set
max_environments_allowedto a higher value per project via the Django admin panel or API to accommodate them.Changes
max_environments_allowedfield (default: 100) to theProjectmodel, following the existing pattern ofmax_segments_allowedandmax_features_allowedEnvironmentPermissionsfor bothcreateandcloneactions, raising aValidationErrorwith a clear message when exceededProject.is_too_largepropertyProjectRetrieveSerializermax_environments_allowedto a higher value per project via the Django admin panelHow did you test this code?
test_environment_permissions__create_at_limit__raises_validation_errortest_environment_permissions__create_below_limit__returns_truetest_environment_permissions__clone_at_limit__raises_validation_errortest_environment_permissions__clone_below_limit__returns_truetest_environment_permissions__create_at_limit_with_increased_limit__returns_true(grandfathering)test_is_too_large__environments_exceed_limit__returns_truetest_is_too_large__environments_within_limit__returns_falsemypy --strictandrufflinting