diff --git a/taggit/admin.py b/taggit/admin.py index 9470de14..1ab26989 100644 --- a/taggit/admin.py +++ b/taggit/admin.py @@ -87,6 +87,9 @@ def merge_tags_view(self, request): @admin.action(description="Remove orphaned tags") def remove_orphaned_tags_action(self, request, queryset): - orphaned_tags = Tag.objects.filter(taggit_taggeditem_items=None) - count, _ = orphaned_tags.delete() - self.message_user(request, f"Successfully removed {count} orphaned tags.", level="success") \ No newline at end of file + try: + orphaned_tags = Tag.objects.filter(taggit_taggeditem_items=None) + count, _ = orphaned_tags.delete() + self.message_user(request, f"Successfully removed {count} orphaned tags.", level="success") + except Exception as e: + self.message_user(request, f"An error occurred: {e}", level="error") \ No newline at end of file