[DO NOT MERGE] Experimental unsubscribe feature#2629
Conversation
| return f"{earliest_str} to {latest_str}" | ||
|
|
||
|
|
||
| class UnsubscribeRequestsReports(ModelList): |
Check failure
Code scanning / CodeQL
Missing call to superclass `__init__` during object initialization Error
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 27 days ago
In general, to fix this class of problem, every subclass that overrides __init__ should either call super().__init__(...) or explicitly call the relevant base class’s __init__ with the correct parameters. This ensures that base classes can perform any necessary initialization before or alongside the subclass’s own setup.
For this specific case, the best fix is to update UnsubscribeRequestsReports.__init__ to call ModelList’s initializer via super().__init__() before setting self.items. We do not know what arguments ModelList.__init__ expects, but the safest and most common pattern is that it either takes no parameters or accepts everything via *args, **kwargs. Since UnsubscribeRequestsReports.__init__ currently only accepts service_id and uses it solely to fetch self.items, we will call super().__init__() with no arguments and keep the existing behavior for self.items intact.
Concretely, in app/models/unsubscribe_requests_report.py, inside class UnsubscribeRequestsReports(ModelList), modify the __init__ method so that the first line of the method body is super().__init__(), followed by the existing self.items = self._get_items(service_id). No imports or additional methods are required.
| @@ -72,6 +72,7 @@ | ||
| return service_api_client.get_unsubscribe_reports_summary(service_id) | ||
|
|
||
| def __init__(self, service_id): | ||
| super().__init__() | ||
| self.items = self._get_items(service_id) | ||
|
|
||
| def __getitem__(self, index): |
| ) | ||
|
|
||
|
|
||
| def get_unsubscribe_callback_details(): |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 26 days ago
In general, to fix “explicit returns mixed with implicit returns” you make all code paths return explicitly, including the path that would otherwise fall off the end of the function. If the intended behavior is to return None (a falsy “no data” sentinel), you explicitly return None in the relevant branch or at the end of the function.
For get_unsubscribe_callback_details in app/main/views/api_keys.py, the intended behavior is clearly that: return the unsubscribe callback details when present; otherwise, return a falsy value used by callers to decide there is no configuration. The simplest change that preserves current functionality is to add an explicit return None when current_service.service_unsubscribe_callback_api is falsy. Concretely, modify lines 483–487 so that they contain an else block with return None, or place return None after the if block. No new imports or helpers are required; this is just a small change in the function body.
| @@ -485,6 +485,7 @@ | ||
| return service_api_client.get_service_unsubscribe_callback_api( | ||
| current_service.id, current_service.service_unsubscribe_callback_api[0] | ||
| ) | ||
| return None | ||
|
|
||
|
|
||
| @main.route( |
| def __len__(self): | ||
| return len(self.items) | ||
|
|
||
| def get_by_batch_id(self, batch_id): |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 27 days ago
In general, to fix “explicit returns mixed with implicit (fall through) returns”, ensure every control-flow path in the function has an explicit return (even if returning None). In this case, get_by_batch_id either returns a report or raises via abort(404). To make this explicit and satisfy the checker, we can add a return statement after the abort(404) call. Because abort(404) raises an exception, the new return is unreachable at runtime and does not change behavior, but it makes it clear to static analysis that no path falls through implicitly.
Concretely, in app/models/unsubscribe_requests_report.py, in UnsubscribeRequestsReports.get_by_batch_id, append return None (or return without a value) immediately after the abort(404) line. No imports or other definitions are needed, and no other functions need to be changed.
| @@ -89,6 +89,7 @@ | ||
| report.all_reports = self | ||
| return report | ||
| abort(404) | ||
| return None | ||
|
|
||
| def get_unbatched_report(self): | ||
| for item in self.items: |
| return report | ||
| abort(404) | ||
|
|
||
| def get_unbatched_report(self): |
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 27 days ago
In general, to fix "explicit returns mixed with implicit (fall through) returns" you ensure that every control-flow path in the function has an explicit return statement, even paths that conceptually never return (for example, because they raise). This makes the function’s contract clearer and avoids confusion or static-analysis warnings about possible None returns.
For get_unbatched_report in app/models/unsubscribe_requests_report.py, the intended behavior is: return a report instance if a non-batched item is found; otherwise abort the request with a 404 error, and never return a normal value. We can preserve this behavior and satisfy the analyzer by adding an explicit return after the abort(404) call. Because abort(404) raises an exception, that return will never actually execute at runtime, but it makes it explicit that the function does not intend to fall through and return None. Concretely, in the get_unbatched_report method (around lines 93–99), append return None (or simply return) immediately after abort(404). No imports, new methods, or other definitions are required.
| @@ -97,6 +97,7 @@ | ||
| report.all_reports = self | ||
| return report | ||
| abort(404) | ||
| return None | ||
|
|
||
| def batch_unbatched(self): | ||
| unbatched = self.get_unbatched_report() |
🧪 Review environmenthttps://j6sql3xvcwglbyajdu6pfzabbq0xswzd.lambda-url.ca-central-1.on.aws/ |
acks working
|
Closing in favour of a scoped down version: #2671 |
Summary | Résumé
[DO NOT MERGE] Unsubscribe feature
Test instructions | Instructions pour tester la modification
TBD