flagsmith icon indicating copy to clipboard operation
flagsmith copied to clipboard

feat: trigger-webhook-events-on-commiting-change-requests

Open Zaimwa9 opened this issue 9 months ago • 4 comments

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

  • [ ] 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?
  • [x] I have used a Conventional Commit title for this Pull Request

Changes

Solves #2064

Webhook events for FLAG_UPDATED were not triggered when committing a Change Request. This PR resolves that issue.

There are two relevant cases: Feature versioning v2: Webhooks were intentionally skipped when environment_feature_version_id is present (cf in test_webhooks_are_not_called_for_feature_state_with_environment_feature_version)

Uncommitted Change Requests (this PR's focus): When creating a Change Request, associated FeatureState objects are created immediately. At this point, post_save triggers (now suppressed) were sending a half empty event while the state was not live. However, when the Change Request is committed, the associated feature states are bulk updated—bypassing signals—and no webhook is triggered.

I intentionally avoided relying on the post_save signal during commit because Change Request FeatureStates are new records without version when initially created. Their history reflect the draft state, meaning enabled matches the future committed values. This leads to new_state == old_state in the webhook payload. So resolving FeatureState based on the previous live version ensure that we pass in the correct diff

Fix: On commit, we now fetch the latest live FeatureState (from DB, not history) and explicitly call trigger_feature_state_change_webhooks() with both the new and previous live state

How did you test this code?

  • Added tests
  • Built a local webhook server

Zaimwa9 avatar May 19 '25 08:05 Zaimwa9

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 3:21pm
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 3:21pm
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2025 3:21pm

vercel[bot] avatar May 19 '25 08:05 vercel[bot]

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-5464 Finished :white_check_mark: Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-5464 Finished :white_check_mark: Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-5464 Finished :white_check_mark: Results :white_check_mark:
ghcr.io/flagsmith/flagsmith-api:pr-5464 Finished :white_check_mark: Results :white_check_mark:
ghcr.io/flagsmith/flagsmith:pr-5464 Finished :white_check_mark: Results :white_check_mark:
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5464 Finished :white_check_mark: Results :white_check_mark:

github-actions[bot] avatar May 19 '25 08:05 github-actions[bot]

Uffizzi Ephemeral Environment Deploying

:cloud: https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/5464

:gear: Updating now by workflow run 15257521630.

What is Uffizzi? Learn more!

github-actions[bot] avatar May 19 '25 08:05 github-actions[bot]

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.68%. Comparing base (365ad46) to head (43eac19). Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5464      +/-   ##
==========================================
+ Coverage   97.66%   97.68%   +0.02%     
==========================================
  Files        1237     1240       +3     
  Lines       43473    43914     +441     
==========================================
+ Hits        42456    42897     +441     
  Misses       1017     1017              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar May 19 '25 08:05 codecov[bot]

Closing to be replaced with #5790

Zaimwa9 avatar Jul 28 '25 14:07 Zaimwa9