fix: multiple environmnet document queued#7531
Open
SahilJat wants to merge 3 commits into
Open
Conversation
|
@SahilJat is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Closes #7492
Eliminates duplicate
Environment.write_environment_documentscallsthat occurred on every
EnvironmentFeatureVersion.publish()acrossall publish paths (standard, API, and Change Requests).
Root cause
Three paths were all independently scheduling the same document rebuild:
update_environment_documentreceiver always calledrebuild_environment_document.delay()including for immediatepublishes already handled by the audit log path
AFTER_CREATEhook firedprocess_environment_updatewhich writes the document and broadcastsSSE (this is the correct canonical path for immediate publishes)
ChangeRequestCommitService._publish_environment_feature_versionsmanually called both
rebuild_environment_document.delay()andtrigger_update_version_webhooks.delay()before sending the signal,causing duplicates since the signal receivers handle both
Changes
api/features/versioning/receivers.py—update_environment_documentnow returns early when
live_fromisNoneor in the past (immediatepublish). Path B (audit log) handles immediate writes and SSE.
Scheduled publishes (
live_from > now) still go through Path A sothe document is rebuilt at the correct time.
api/core/workflows_services.py— removed manualrebuild_environment_document.delay()andtrigger_update_version_webhooks.delay()calls from_publish_environment_feature_versions. The signal send that followsalready triggers both via the registered receivers, making the manual
calls redundant across all Change Request publish paths.
api/tests/unit/features/versioning/test_unit_versioning_receivers.py— new test file covering both the immediate-publish skip and the
scheduled-publish delay behaviour.
api/tests/unit/features/workflows/core/test_unit_workflows_models.py— updated
test_change_request_commit__v2_versioning__publishes_environment_feature_versionsto assert on the signal send rather than the now-removed manual task
calls.
How did you test this code?
api/tests/unit/features/versioning/test_unit_versioning_receivers.py:test_update_environment_document__immediate_publish__does_not_schedule_rebuild— verifies
rebuild_environment_document.delayis not called forimmediate publishes
test_update_environment_document__scheduled_publish__schedules_rebuild_at_live_from— verifies the task is scheduled with the correct
delay_untilforfuture publishes
signal is sent rather than asserting on the removed manual task calls
cd api python -m pytest tests/unit/features/versioning/test_unit_versioning_receivers.py -v python -m pytest tests/unit/features/workflows/core/test_unit_workflows_models.py -v