Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions osf/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
from django.contrib.auth.hashers import check_password
from django.contrib.auth.models import PermissionsMixin
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldDoesNotExist
from django.dispatch import receiver
from django.db import models
Expand Down Expand Up @@ -877,6 +878,29 @@ def merge_user(self, user):
except Exception as e:
logger.exception(f'Failed to SHARE reindex preprint {preprint._id} during user merge: {e}')

from osf.models import AbstractNode, Preprint
from addons.osfstorage.models import OsfStorageFile
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move django and addon imports to the top of the file. Circular import error should not occur in this case I think

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circular import errors exist from my side for

  from django.contrib.contenttypes.models import ContentType
  from osf.models import AbstractNode, Preprint
image image

node_ctype = ContentType.objects.get_for_model(AbstractNode)
preprint_ctype = ContentType.objects.get_for_model(Preprint)
nodes_files_to_reindex = OsfStorageFile.objects.filter(
target_object_id__in=user.contributed.values_list('id', flat=True), target_content_type=node_ctype,
guids__isnull=False
)
preprints_files_to_reindex = OsfStorageFile.objects.filter(
target_object_id__in=user.preprints.values_list('id', flat=True), target_content_type=preprint_ctype,
guids__isnull=False
)
for file in nodes_files_to_reindex.iterator(chunk_size=100):
try:
update_share(file)
except Exception as e:
logger.exception(f'Failed to SHARE reindex file {file._id} during user merge: {e}')
for file in preprints_files_to_reindex.iterator(chunk_size=100):
try:
update_share(file)
except Exception as e:
logger.exception(f'Failed to SHARE reindex preprints file {file._id} during user merge: {e}')

def _merge_users_preprints(self, user):
"""
Preprints use guardian. The PreprintContributor table stores order and bibliographic information.
Expand Down