🐛 Prevent sending empty notifications to webhook#417
Open
septikus wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue where empty notifications were still being sent to the webhook listener when no new campsites were found during a search.
Motivation and Context
When running
camplyin continuous search mode, it periodically checks for campsite availability. If a search completes and finds 0 new campsites (either because nothing was found, or all found sites were already logged), the notification pipeline was still being triggered.For the webhook provider, this resulted in an empty POST request (containing
{"campsites": []}) being sent to the configuredWEBHOOK_URLon every single polling interval. This caused unnecessary network traffic and noise for webhook listeners.Changes
camply/search/base_search.py: Added a check (if new_campsites:) to only call_handle_notificationswhen new campsites are actually discovered.camply/notifications/webhook.py: Added a guard clause insend_campsitesto return early if thecampsiteslist is empty, preventing empty POST requests.Has This Been Tested?
I have added unit tests in
tests/test_notifications.pyto verify these changes:test_no_notifications_when_no_new_campsites: Verifies thatMultiNotifierProvider.send_campsitesis not called when_continuous_search_retryfinds no new campsites.test_webhook_notifier_empty_campsites: Verifies thatWebhookNotificationsdoes not make a POST request whensend_campsitesis called with an empty list.Test Configuration
PUSHOVER_PUSH_USER=dummy PUSHOVER_PUSH_TOKEN=dummy pytest -o addopts="" -W ignore tests/test_notifications.pyChecklist:
BUMP_MAJOR,BUMP_MINOR, orBUMP_PATCHlabel to this PR to increment the version.pre_commiton all my code