-
Notifications
You must be signed in to change notification settings - Fork 355
[hotfix/26.1.5] [ENG-10019] [ENG-10024] [ENG-10039] NR post-release bug-fixes that don't require migration #11541
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
Merged
cslzchen
merged 1 commit into
CenterForOpenScience:hotfix/26.1.5
from
Ostap-Zherebetskyi:hotfix/moderators_subscriptions_and_duplicates
Jan 8, 2026
+64
−5
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
55 changes: 55 additions & 0 deletions
55
osf/management/commands/remove_duplicate_notification_subscriptions.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| from django.core.management.base import BaseCommand | ||
| from django.db import transaction | ||
| from django.db.models import OuterRef, Exists | ||
|
|
||
| from osf.models import NotificationSubscription | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = ( | ||
| 'Remove duplicate NotificationSubscription records, keeping only ' | ||
| 'the highest-id record per (user, content_type, object_id, notification_type).' | ||
| ) | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| '--dry', | ||
| action='store_true', | ||
| help='Show how many rows would be deleted without deleting anything.', | ||
| ) | ||
|
|
||
| def handle(self, *args, **options): | ||
| self.stdout.write('Finding duplicate NotificationSubscription records…') | ||
|
|
||
| to_remove = NotificationSubscription.objects.filter( | ||
| Exists( | ||
| NotificationSubscription.objects.filter( | ||
| user_id=OuterRef('user_id'), | ||
| content_type_id=OuterRef('content_type_id'), | ||
| object_id=OuterRef('object_id'), | ||
| notification_type_id=OuterRef('notification_type_id'), | ||
| _is_digest=OuterRef('_is_digest'), | ||
| id__gt=OuterRef('id'), # keep most recent record | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| count = to_remove.count() | ||
| self.stdout.write(f"Duplicates to remove: {count}") | ||
|
|
||
| if options['dry']: | ||
| self.stdout.write( | ||
| self.style.WARNING('Dry run enabled — no records were deleted.') | ||
| ) | ||
| return | ||
|
|
||
| if count == 0: | ||
| self.stdout.write(self.style.SUCCESS('No duplicates found.')) | ||
| return | ||
|
|
||
| with transaction.atomic(): | ||
| deleted, _ = to_remove.delete() | ||
cslzchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| self.stdout.write( | ||
| self.style.SUCCESS(f"Successfully removed {deleted} duplicate records.") | ||
| ) | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.