Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 54 commits into
base: main
Choose a base branch
from

Conversation

Zaimwa9
Copy link
Contributor

@Zaimwa9 Zaimwa9 commented May 19, 2025

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

  • 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?
  • 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 and others added 23 commits April 25, 2025 16:28
@Zaimwa9 Zaimwa9 requested a review from a team as a code owner May 19, 2025 08:35
@Zaimwa9 Zaimwa9 requested review from khvn26 and removed request for a team May 19, 2025 08:35
Copy link

vercel bot commented May 19, 2025

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

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview May 26, 2025 3:28pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview May 26, 2025 3:28pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview May 26, 2025 3:28pm

@Zaimwa9 Zaimwa9 marked this pull request as draft May 19, 2025 08:35
@github-actions github-actions bot added the api Issue related to the REST API label May 19, 2025
Copy link
Contributor

github-actions bot commented May 19, 2025

Docker builds report

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

@Zaimwa9 Zaimwa9 mentioned this pull request May 22, 2025
4 tasks
@Zaimwa9 Zaimwa9 requested a review from a team as a code owner May 26, 2025 15:25
@Zaimwa9 Zaimwa9 requested review from kyle-ssg and removed request for a team May 26, 2025 15:25
@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard feature New feature or request and removed feature New feature or request labels May 26, 2025
@@ -129,7 +126,10 @@ const PermissionControl: React.FC<PermissionControlProps> = ({

const isViewRequiredAndNotAllowed =
isViewPermissionRequired && !isViewPermissionAllowed
const isChecked = !disabled && isPermissionEnabled && (!isViewPermissionRequired || isViewPermissionAllowed)
const isChecked =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

pre-commit artifact

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 feature New feature or request front-end Issue related to the React Front End Dashboard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants