Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Apprise 2: keep the handler bool contract for notify() results

Omega (QA)6983f1b083cd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 708e2c9..3171b20 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@
- _Files: `backend/config.py`, `backend/db_handler.py`, `backend/fix_permissions.py`, `backend/migrations/apply_migrations.py`, `Docker/entrypoint.sh`, `env.example`, `unraid/warracker.xml`, `tests/conftest.py`, `.github/workflows/tests.yml`, `tests/test_db_credentials_required.py`_
- **PKCE (S256) for OIDC sign-in (#288, suggested by John in Discord):** the OIDC authorization code flow now uses PKCE when the identity provider supports it. At startup Warracker reads the provider discovery document, and if it advertises S256 in `code_challenge_methods_supported`, the client is registered with PKCE enabled, so the authorization code is bound to a verifier only Warracker holds. Providers that do not advertise S256 keep the existing plain flow, and if the discovery document cannot be read at startup, sign-in continues without PKCE and a warning is logged. Nothing changes in the OIDC settings screens, and existing provider configurations need no changes.
- _Files: `backend/oidc_handler.py`, `tests/test_oidc_pkce.py`_
+- **Dependency updates: Authlib 1.9.5 and Apprise 2.2.0 (#291, #256):** Authlib moves from 1.9.2 to 1.9.5, three upstream security releases: 1.9.3 refuses form_post responses to non-http(s) redirect URIs in the implicit and hybrid grants, 1.9.4 fixes ID-JAG user resolution for multi-tenant providers, and 1.9.5 completes the fix for CVE-2026-114615 by refusing public keys and certificates as HMAC secrets. Warracker uses Authlib as an OIDC client rather than an authorization server, so these are taken as auth-stack hygiene alongside the new PKCE support. Apprise moves from 1.13.1 to 2.2.0, a major release carrying the upstream security fix GHSA-cfp4-m43r-v9q4 and a dozen new notification services. Behavior changes in Apprise 2 that touch notifications: `notify()` returns a detailed result object instead of True/False/None, deliveries to multiple targets run in parallel by default, and retries are tracked per target. Warracker reads the result the same way it always has, sent only when every target was delivered to, and the handler now coerces the result to a plain bool, so test, custom, and expiration notifications behave identically for callers. The deprecated Apprise options removed in 2.0 were not in use.
+ - _Files: `backend/requirements.txt`, `backend/apprise_handler.py`, `tests/test_apprise_notify_result.py`_
## 1.0.6 - 2026-11-10
diff --git a/backend/apprise_handler.py b/backend/apprise_handler.py
index d95a9fd..bf96235 100644
--- a/backend/apprise_handler.py
+++ b/backend/apprise_handler.py
@@ -1,6 +1,12 @@
"""
Apprise Notification Handler for Warracker
Handles sending notifications via Apprise for warranty expirations and other events
+
+Apprise 2 note: notify() returns an AppriseResult object instead of the
+1.x True/False/None. bool(result) is True only when every target was
+delivered to, which matches how Warracker has always read the result,
+and every notify() return below is coerced with bool() so the handler
+methods keep their documented bool contract.
"""
import os
@@ -207,14 +213,14 @@ class AppriseNotificationHandler:
title = f"{self.title_prefix} Test Notification"
body = "This is a test notification from Warracker to verify your Apprise configuration is working correctly."
- return test_apprise.notify(title=title, body=body)
+ return bool(test_apprise.notify(title=title, body=body))
elif self.enabled and self.apprise_obj:
# Use configured URLs
title = f"{self.title_prefix} Test Notification"
body = "This is a test notification from Warracker to verify your Apprise configuration is working correctly."
- return self.apprise_obj.notify(title=title, body=body)
+ return bool(self.apprise_obj.notify(title=title, body=body))
else:
logger.warning("Apprise not enabled or configured for test notification")
return False
@@ -319,7 +325,7 @@ class AppriseNotificationHandler:
body = "\n".join(body_lines)
- return self.apprise_obj.notify(title=title, body=body)
+ return bool(self.apprise_obj.notify(title=title, body=body))
except Exception as e:
logger.error(f"Error sending expiration batch notification: {e}")
@@ -343,12 +349,12 @@ class AppriseNotificationHandler:
return False
full_title = f"{self.title_prefix} {title}"
- return custom_apprise.notify(title=full_title, body=message)
+ return bool(custom_apprise.notify(title=full_title, body=message))
elif self.is_available():
# Use configured URLs
full_title = f"{self.title_prefix} {title}"
- return self.apprise_obj.notify(title=full_title, body=message)
+ return bool(self.apprise_obj.notify(title=full_title, body=message))
else:
logger.warning("No Apprise configuration available for custom notification")
return False
@@ -476,7 +482,7 @@ class AppriseNotificationHandler:
body = "\n".join(body_lines)
- return self.apprise_obj.notify(title=title, body=body)
+ return bool(self.apprise_obj.notify(title=title, body=body))
except Exception as e:
logger.error(f"Error sending global expiration batch notification: {e}")
@@ -573,7 +579,7 @@ class AppriseNotificationHandler:
body = "\n".join(body_lines)
- return self.apprise_obj.notify(title=title, body=body)
+ return bool(self.apprise_obj.notify(title=title, body=body))
except Exception as e:
logger.error(f"Error sending individual expiration batch notification: {e}")
diff --git a/tests/test_apprise_notify_result.py b/tests/test_apprise_notify_result.py
new file mode 100644
index 0000000..c69d2ed
--- /dev/null
+++ b/tests/test_apprise_notify_result.py
@@ -0,0 +1,131 @@
+"""Apprise 2 notify() result handling (#256).
+
+Apprise 2 changed notify() to return an AppriseResult object instead of
+the 1.x True/False/None. The handler methods are documented to return
+bool, and every caller (admin test/custom endpoints, the expiration
+notification flow) reads the result by truthiness. These tests pin the
+contract: handler methods return real bools, with True only when the
+delivery fully succeeded, under both a result-object stub and the real
+Apprise library delivering to a local endpoint.
+"""
+import json
+import threading
+from http.server import BaseHTTPRequestHandler, HTTPServer
+
+import pytest
+
+from backend import apprise_handler as handler_module
+from backend.apprise_handler import AppriseNotificationHandler
+
+
+class FakeResult:
+ """Stands in for Apprise 2's AppriseResult: truthy only on success."""
+
+ def __init__(self, ok):
+ self._ok = ok
+
+ def __bool__(self):
+ return self._ok
+
+
+class FakeAppriseObj:
+ def __init__(self, ok):
+ self._ok = ok
+ self.calls = []
+
+ def notify(self, title=None, body=None):
+ self.calls.append((title, body))
+ return FakeResult(self._ok)
+
+
+def _handler_with(obj):
+ handler = AppriseNotificationHandler.__new__(AppriseNotificationHandler)
+ handler.apprise_obj = obj
+ handler.enabled = True
+ handler.notification_urls = ["json://example"]
+ handler.title_prefix = "[Warracker]"
+ handler.expiration_days = [7]
+ return handler
+
+
[email protected](autouse=True)
+def _apprise_available(monkeypatch):
+ monkeypatch.setattr(handler_module, "APPRISE_AVAILABLE", True)
+
+
+def test_test_notification_returns_real_bool():
+ ok_handler = _handler_with(FakeAppriseObj(True))
+ result = ok_handler.send_test_notification()
+ assert result is True
+
+ failing_handler = _handler_with(FakeAppriseObj(False))
+ result = failing_handler.send_test_notification()
+ assert result is False
+
+
+def test_expiration_batch_returns_real_bool():
+ warranties = [{"product_name": "Widget", "expiration_date": "2030-01-01"}]
+
+ ok_handler = _handler_with(FakeAppriseObj(True))
+ assert ok_handler._send_expiration_batch(warranties, 7) is True
+
+ failing_handler = _handler_with(FakeAppriseObj(False))
+ assert failing_handler._send_expiration_batch(warranties, 7) is False
+
+
+def test_custom_notification_returns_real_bool():
+ ok_handler = _handler_with(FakeAppriseObj(True))
+ assert ok_handler.send_custom_notification("Title", "Message") is True
+
+ failing_handler = _handler_with(FakeAppriseObj(False))
+ assert failing_handler.send_custom_notification("Title", "Message") is False
+
+
+class _CaptureHandler(BaseHTTPRequestHandler):
+ posts = []
+
+ def do_POST(self):
+ length = int(self.headers.get("Content-Length", 0))
+ body = self.rfile.read(length)
+ _CaptureHandler.posts.append(body)
+ self.send_response(200)
+ self.end_headers()
+
+ def log_message(self, *args):
+ pass
+
+
+def capture_server():
+ _CaptureHandler.posts = []
+ server = HTTPServer(("127.0.0.1", 0), _CaptureHandler)
+ thread = threading.Thread(target=server.serve_forever, daemon=True)
+ thread.start()
+ yield server.server_address[1]
+ server.shutdown()
+
+
+def test_real_apprise_delivery_to_local_endpoint(capture_server):
+ import apprise
+
+ apprise_obj = apprise.Apprise()
+ assert apprise_obj.add(f"json://127.0.0.1:{capture_server}") is True
+
+ handler = _handler_with(apprise_obj)
+ assert handler.send_test_notification() is True
+
+ assert len(_CaptureHandler.posts) == 1
+ payload = json.loads(_CaptureHandler.posts[0])
+ assert "Test Notification" in payload.get("title", "")
+ assert "test notification" in payload.get("message", "").lower()
+
+
+def test_real_apprise_failure_returns_false():
+ import apprise
+
+ apprise_obj = apprise.Apprise()
+ # Port 1 is closed: the delivery fails and must read as False.
+ assert apprise_obj.add("json://127.0.0.1:1") is True
+
+ handler = _handler_with(apprise_obj)
+ assert handler.send_test_notification() is False