Skip to content

[DO NOT MERGE] Experimental unsubscribe feature#2629

Closed
smcmurtry wants to merge 4 commits intomainfrom
feat/unsubscribe
Closed

[DO NOT MERGE] Experimental unsubscribe feature#2629
smcmurtry wants to merge 4 commits intomainfrom
feat/unsubscribe

Conversation

@smcmurtry
Copy link
Copy Markdown
Contributor

Summary | Résumé

[DO NOT MERGE] Unsubscribe feature

Test instructions | Instructions pour tester la modification

TBD

return f"{earliest_str} to {latest_str}"


class UnsubscribeRequestsReports(ModelList):

Check failure

Code scanning / CodeQL

Missing call to superclass `__init__` during object initialization Error

This class does not call
ModelList.__init__
during initialization. (
UnsubscribeRequestsReports.__init__
may be missing a call to a base class __init__)

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.

Suggested changeset 1
app/models/unsubscribe_requests_report.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/models/unsubscribe_requests_report.py b/app/models/unsubscribe_requests_report.py
--- a/app/models/unsubscribe_requests_report.py
+++ b/app/models/unsubscribe_requests_report.py
@@ -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):
EOF
@@ -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):
Copilot is powered by AI and may make mistakes. Always verify output.
)


def get_unsubscribe_callback_details():

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.

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.

Suggested changeset 1
app/main/views/api_keys.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/main/views/api_keys.py b/app/main/views/api_keys.py
--- a/app/main/views/api_keys.py
+++ b/app/main/views/api_keys.py
@@ -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(
EOF
@@ -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(
Copilot is powered by AI and may make mistakes. Always verify output.
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

Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.

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.

Suggested changeset 1
app/models/unsubscribe_requests_report.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/models/unsubscribe_requests_report.py b/app/models/unsubscribe_requests_report.py
--- a/app/models/unsubscribe_requests_report.py
+++ b/app/models/unsubscribe_requests_report.py
@@ -89,6 +89,7 @@
                 report.all_reports = self
                 return report
         abort(404)
+        return None
 
     def get_unbatched_report(self):
         for item in self.items:
EOF
@@ -89,6 +89,7 @@
report.all_reports = self
return report
abort(404)
return None

def get_unbatched_report(self):
for item in self.items:
Copilot is powered by AI and may make mistakes. Always verify output.
return report
abort(404)

def get_unbatched_report(self):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note

Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.

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.

Suggested changeset 1
app/models/unsubscribe_requests_report.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/models/unsubscribe_requests_report.py b/app/models/unsubscribe_requests_report.py
--- a/app/models/unsubscribe_requests_report.py
+++ b/app/models/unsubscribe_requests_report.py
@@ -97,6 +97,7 @@
                 report.all_reports = self
                 return report
         abort(404)
+        return None
 
     def batch_unbatched(self):
         unbatched = self.get_unbatched_report()
EOF
@@ -97,6 +97,7 @@
report.all_reports = self
return report
abort(404)
return None

def batch_unbatched(self):
unbatched = self.get_unbatched_report()
Copilot is powered by AI and may make mistakes. Always verify output.
@github-actions
Copy link
Copy Markdown

acks working
@smcmurtry
Copy link
Copy Markdown
Contributor Author

Closing in favour of a scoped down version: #2671

@smcmurtry smcmurtry closed this Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants