Skip to content
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

fix(webhooks): prevent raise on give up #3295

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/integrations/rudderstack/rudderstack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import typing

import rudder_analytics
from rudderstack import analytics as rudder_analytics

from environments.identities.models import Identity
from environments.identities.traits.models import Trait
Expand Down
118 changes: 56 additions & 62 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ readme = "readme.md"
[tool.poetry.dependencies]
python = ">=3.10,<3.12"
django = "~3.2.23"
rudder-sdk-python = "~1.0.5"
analytics-python = "~1.4.0"
backoff = "~1.10.0"
rudder-sdk-python = "~2.0.2"
segment-analytics-python = "~2.2.3"
backoff = "~2.2.1"
appdirs = "~1.4.4"
django-cors-headers = "~3.5.0"
djangorestframework = "~3.12.1"
Expand Down
20 changes: 20 additions & 0 deletions api/tests/unit/webhooks/test_unit_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest import TestCase, mock

import pytest
import responses
from core.constants import FLAGSMITH_SIGNATURE_HEADER
from pytest_django.fixtures import SettingsWrapper
from pytest_mock import MockerFixture
Expand All @@ -21,6 +22,7 @@
WebhookEventType,
WebhookType,
call_environment_webhooks,
call_integration_webhook,
call_organisation_webhooks,
call_webhook_with_failure_mail_after_retries,
trigger_sample_webhook,
Expand Down Expand Up @@ -316,3 +318,21 @@ def test_call_webhook_with_failure_mail_after_retries_does_not_retry_if_not_usin
# Then
assert requests_post_mock.call_count == 1
send_failure_email_mock.assert_called_once()


@responses.activate()
def test_call_integration_webhook_does_not_raise_error_on_backoff_give_up(
mocker: MockerFixture,
) -> None:
# Given
url = "https://test.com/webhook"
config = mocker.MagicMock(secret=None, url=url)

responses.add(url=url, method="POST", body=json.dumps({}), status=400)

# When
result = call_integration_webhook(config, data={})

# Then
# we don't get a result from the function, but no exception is raised
assert result is None
2 changes: 2 additions & 0 deletions api/webhooks/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def trigger_sample_webhook(
wait_gen=backoff.expo,
exception=requests.exceptions.RequestException,
max_tries=settings.WEBHOOK_BACKOFF_RETRIES,
raise_on_giveup=False,
giveup_log_level=logging.WARNING,
)
def _call_webhook(
webhook: AbstractBaseWebhookModel,
Expand Down