Skip to content

fix(webhooks): accept 2xx status codes in webhook test endpoint#7992

Open
Marnie0415 wants to merge 1 commit into
Flagsmith:mainfrom
Marnie0415:fix/webhook-test-status-codes
Open

fix(webhooks): accept 2xx status codes in webhook test endpoint#7992
Marnie0415 wants to merge 1 commit into
Flagsmith:mainfrom
Marnie0415:fix/webhook-test-status-codes

Conversation

@Marnie0415

@Marnie0415 Marnie0415 commented Jul 11, 2026

Copy link
Copy Markdown

Changes

The webhook test endpoint (POST /api/v1/webhooks/test/) previously treated any non-200 response as a failure. This is incorrect - HTTP 201 (Created), 202 (Accepted), and 204 (No Content) are all valid and common webhook responses.

Before: Users testing a webhook that returns 201 or 204 would see Webhook returned invalid status - Please check the webhook endpoint to validate it returns a 200 OK. even though their webhook is working correctly.

After: Any 2xx response (200-299) is treated as successful. Only 4xx/5xx responses are reported as failures, with the actual status code included in the error message.

How did you test this code?

  • Verified the change only affects the condition check (!= 200 -> >= 400)
  • No other code paths depend on this specific status code check
  • The success response still includes the actual status code for debugging
  • Updated test assertions in test_unit_webhooks.py to match the new error messages

@Marnie0415 Marnie0415 requested a review from a team as a code owner July 11, 2026 19:06
@Marnie0415 Marnie0415 requested review from khvn26 and removed request for a team July 11, 2026 19:06
@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a600e66e-46a4-4924-9d61-8a877d50785e

📥 Commits

Reviewing files that changed from the base of the PR and between 8888e4c and c595f84.

📒 Files selected for processing (2)
  • api/tests/unit/webhooks/test_unit_webhooks.py
  • api/webhooks/views.py

📝 Walkthrough

Walkthrough

WebhookViewSet.test now treats webhook responses with HTTP status codes below 400 as successful and codes from 400 onwards as errors. Error responses include the actual status code in the body, with updated unit-test expectations. Network exception handling remains unchanged.

Estimated code review effort: 2 (Simple) | ~5 minutes


Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the api Issue related to the REST API label Jul 11, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
api/webhooks/views.py (1)

50-58: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Align the webhook error payload with the existing test assertions. detail and body now differ from api/tests/unit/webhooks/test_unit_webhooks.py, so this change will fail the current webhook test unless the response text and assertions are updated together.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f9f7ee49-c4fd-41aa-8ca0-d1ad7707e07b

📥 Commits

Reviewing files that changed from the base of the PR and between 1c73453 and 8888e4c.

📒 Files selected for processing (1)
  • api/webhooks/views.py

The webhook test endpoint previously treated any non-200 response as a
failure. This is incorrect — HTTP 201 (Created), 202 (Accepted), and
204 (No Content) are all valid webhook responses.

Change the condition from \status_code != 200\ to \status_code >= 400\
so that any 2xx response is considered successful. Also update the
error message to include the actual status code instead of telling
users to return a 200 OK.
@Marnie0415 Marnie0415 force-pushed the fix/webhook-test-status-codes branch from 8888e4c to c595f84 Compare July 11, 2026 19:10
@Marnie0415

Copy link
Copy Markdown
Author

Note: the existing test in \ est_send_test_webhook__various_error_status_codes__returns_correct_response\ has been updated to match the new error message and body format. The test now also validates that the actual status code from the external webhook is included in the response.

@Marnie0415

Copy link
Copy Markdown
Author

Updated test assertions in test_unit_webhooks.py to match the new error messages.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant