feat(Flag Dependency): Index flag references - #8525
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change adds a Django dependencies application and persistent segment-to-feature references. It maps supported Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to Segment flag dependency indexing and cycle validation now run on every segment update, including metadata-only edits, which adds extra database work to those writes. Behaviour remains correct, so this can be merged with a follow-up to skip the dependency work when segment rules are unchanged. ✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
36dde6b to
b28b065
Compare
b28b065 to
a819d0c
Compare
66804ae to
3608b5e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: ec7252e8-2519-4efa-9575-e09e6a275fe3
📒 Files selected for processing (15)
api/app/settings/common.pyapi/features/dependencies/exceptions.pyapi/features/dependencies/mappers.pyapi/features/dependencies/services.pyapi/features/dependencies/types.pyapi/features/feature_segments/views.pyapi/features/future/services.pyapi/tests/integration/conftest.pyapi/tests/integration/features/conftest.pyapi/tests/integration/features/dependencies/test_segment_management.pyapi/tests/integration/features/future/test_flag_endpoint.pyapi/tests/types.pyapi/tests/unit/features/dependencies/__init__.pyapi/tests/unit/features/dependencies/test_mappers.pydocs/docs/deployment-self-hosting/observability/_events-catalogue.md
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Serialise dependency validation per environment. · services.py:106-170
api/features/dependencies/services.py:106-170
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftSerialise dependency validation per environment.
FeatureSegmentViewSet.perform_createwrites the newFeatureSegmentand then callsvalidate_segment_flag_dependenciesinsidetransaction.atomic(). The validator readsget_overrides_in_effect()fromsegments.serviceswithoutselect_for_update.In an environment with
use_v2_feature_versioning=False, two requests can add these edges concurrently:
- feature A overrides a segment that references feature B;
- feature B overrides a segment that references feature A.
Each transaction can validate before the other transaction commits. Both validations then pass, and both
FeatureSegmentrows commit, leaving the cycle A → B → A.SegmentFlagReferencehas only foreign keys, andFeatureSegmentuniqueness covers only identical rows. No database constraint enforces an acyclic graph.Lock a common row for each affected environment in a stable order before the dependency graph query, and hold the lock through the surrounding transaction's commit. Alternatively, enforce the acyclic invariant at the database boundary.
🟠 Major · Defer dependency indexing from segment writes. · serializers.py:224-244
api/segments/serializers.py:224-244
🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy liftDefer dependency indexing from segment writes.
SegmentViewSetusesSegmentSerializerfor segment writes. The serializer callsindex_segment_flag_references()insidetransaction.atomic(). For indexed rules, this performs a feature lookup, reads and deletes existingSegmentFlagReferencerows, bulk-inserts replacements, and emits dependency log events. Updates also runvalidate_segment_flag_dependencies(), which queries dependency edges synchronously.This extends the segment-write transaction and adds database and logging work to the request path. Defer indexing, or redesign the write path to preserve validation and consistency without this synchronous work.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: 5789cfba-8937-4d99-9400-b24e9d302845
📒 Files selected for processing (2)
api/features/dependencies/mappers.pyapi/tests/integration/features/dependencies/test_segment_management.py
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.
khvn26
left a comment
There was a problem hiding this comment.
LGTM bar a couple questions around the circular dependency validation. Good job 👍
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Reject cross-project segment overrides before dependency validation. · services.py:24-62
api/features/dependencies/services.py:24-62
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winReject cross-project segment overrides before dependency validation.
FeatureSegmentCreateSerializeraccepts independentfeature,segment, andenvironmentforeign keys.FeatureSegmentPermissionschecks only the environment permission, andget_overrides_in_effect()returns a global queryset. A request can therefore attach a project B segment to a project A feature and environment.
SegmentFlagReferencedoes not enforce matching projects._get_dependency_edges()then joins its prerequisite feature names without a project filter. If the project B segment references a feature namedF, validation can treat that reference as a dependency of project A's featureFand raise a falseCircularDependencyError.Require matching project IDs when creating
FeatureSegmentandSegmentFlagReferencerows. Also scope dependency traversal to the environment's project as a defensive check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: cff53a2f-d919-439a-bd44-f3dbcd06aead
📒 Files selected for processing (3)
api/features/dependencies/services.pyapi/tests/unit/features/dependencies/test_services.pydocs/docs/deployment-self-hosting/observability/_events-catalogue.md
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
8d64135 to
ed3decf
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: 95500cc5-6a71-4f1e-8196-49606291e624
📒 Files selected for processing (25)
api/app/settings/common.pyapi/features/dependencies/__init__.pyapi/features/dependencies/apps.pyapi/features/dependencies/exceptions.pyapi/features/dependencies/mappers.pyapi/features/dependencies/migrations/0001_initial.pyapi/features/dependencies/migrations/__init__.pyapi/features/dependencies/models.pyapi/features/dependencies/services.pyapi/features/dependencies/types.pyapi/features/feature_segments/views.pyapi/features/future/services.pyapi/features/views.pyapi/segments/serializers.pyapi/segments/services.pyapi/tests/integration/conftest.pyapi/tests/integration/features/conftest.pyapi/tests/integration/features/dependencies/test_segment_management.pyapi/tests/integration/features/future/test_flag_endpoint.pyapi/tests/types.pyapi/tests/unit/features/dependencies/__init__.pyapi/tests/unit/features/dependencies/test_mappers.pyapi/tests/unit/features/dependencies/test_services.pyapi/tests/unit/segments/test_unit_segments_services.pydocs/docs/deployment-self-hosting/observability/_events-catalogue.md
💤 Files with no reviewable changes (3)
- api/features/dependencies/init.py
- api/features/dependencies/migrations/init.py
- api/tests/unit/features/dependencies/init.py
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.
…cy-flag-reference
I have added information todocs/if required so people know about the feature.Changes
Closes #8412
This implements the support foundation for flag dependency in the Management API:
How did you test this code?
A whole lotta tests included.