Skip to content

Commit

Permalink
Fix update_search for subclasses of VersionedGuidMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Jan 14, 2025
1 parent 4b1bc6a commit 72f6b00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions osf/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,10 @@ def get_semantic_iri(self):
raise ValueError(f'no osfid for {self} (cannot build semantic iri)')
return osfid_iri(_osfid)

def update_search(self, skip_share=False):
"""Subclasses must implement `update_search()` with kwarg `skip_share=False`."""
raise NotImplementedError()

@receiver(post_save)
def ensure_guid(sender, instance, **kwargs):
"""Generate guid if it doesn't exist for subclasses of GuidMixin except for subclasses of VersionedGuidMixin
Expand Down
10 changes: 8 additions & 2 deletions osf/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,10 @@ def set_subjects(self, new_subjects, auth, add_log=True, skip_share=False):

self.save()
if hasattr(self, 'update_search'):
self.update_search(skip_share=skip_share)
from osf.models.base import VersionedGuidMixin
if isinstance(self, VersionedGuidMixin):
self.update_search(skip_share=skip_share)
self.update_search()

def set_subjects_from_relationships(self, subjects_list, auth, add_log=True, skip_share=False):
""" Helper for setting M2M subjects field from list of flattened subjects received from UI.
Expand All @@ -1162,7 +1165,10 @@ def set_subjects_from_relationships(self, subjects_list, auth, add_log=True, ski

self.save()
if hasattr(self, 'update_search'):
self.update_search(skip_share=skip_share)
from osf.models.base import VersionedGuidMixin
if isinstance(self, VersionedGuidMixin):
self.update_search(skip_share=skip_share)
self.update_search()

def map_subjects_between_providers(self, old_provider, new_provider, auth=None):
"""
Expand Down

0 comments on commit 72f6b00

Please sign in to comment.