Skip to content

fix: multiple environmnet document queued#7531

Open
SahilJat wants to merge 3 commits into
Flagsmith:mainfrom
SahilJat:fix/double-environment-in-v2
Open

fix: multiple environmnet document queued#7531
SahilJat wants to merge 3 commits into
Flagsmith:mainfrom
SahilJat:fix/double-environment-in-v2

Conversation

@SahilJat
Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • [ x ] I have read the Contributing Guide.
  • [ x ] I have added information to docs/ if required so people know about the feature.
  • [ x ] I have filled in the "Changes" section below.
  • [ x ] I have filled in the "How did you test this code" section below.

Changes

Closes #7492

Eliminates duplicate Environment.write_environment_documents calls
that occurred on every EnvironmentFeatureVersion.publish() across
all publish paths (standard, API, and Change Requests).

Root cause

Three paths were all independently scheduling the same document rebuild:

  • Path Aupdate_environment_document receiver always called
    rebuild_environment_document.delay() including for immediate
    publishes already handled by the audit log path
  • Path B — audit log AFTER_CREATE hook fired
    process_environment_update which writes the document and broadcasts
    SSE (this is the correct canonical path for immediate publishes)
  • Path CChangeRequestCommitService._publish_environment_feature_versions
    manually called both rebuild_environment_document.delay() and
    trigger_update_version_webhooks.delay() before sending the signal,
    causing duplicates since the signal receivers handle both

Changes

  • api/features/versioning/receivers.pyupdate_environment_document
    now returns early when live_from is None or in the past (immediate
    publish). Path B (audit log) handles immediate writes and SSE.
    Scheduled publishes (live_from > now) still go through Path A so
    the document is rebuilt at the correct time.
  • api/core/workflows_services.py — removed manual
    rebuild_environment_document.delay() and
    trigger_update_version_webhooks.delay() calls from
    _publish_environment_feature_versions. The signal send that follows
    already 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_versions
    to assert on the signal send rather than the now-removed manual task
    calls.

How did you test this code?

  • Added two unit tests in
    api/tests/unit/features/versioning/test_unit_versioning_receivers.py:
    • test_update_environment_document__immediate_publish__does_not_schedule_rebuild
      — verifies rebuild_environment_document.delay is not called for
      immediate publishes
    • test_update_environment_document__scheduled_publish__schedules_rebuild_at_live_from
      — verifies the task is scheduled with the correct delay_until for
      future publishes
  • Updated the existing Change Request v2 versioning test to verify the
    signal is sent rather than asserting on the removed manual task calls
  • Ran the full unit test suite locally to confirm no regressions
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

@SahilJat SahilJat requested a review from a team as a code owner May 18, 2026 09:00
@SahilJat SahilJat requested review from emyller and removed request for a team May 18, 2026 09:01
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

@SahilJat is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the api Issue related to the REST API label May 18, 2026
@SahilJat SahilJat requested a review from a team as a code owner May 18, 2026 10:12
@github-actions github-actions Bot added the docs Documentation updates label May 18, 2026
@SahilJat SahilJat closed this May 19, 2026
@SahilJat SahilJat reopened this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API docs Documentation updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two environment-document rebuilds enqueued per Feature Versioning v2 publish

1 participant