Skip to content

Commit

Permalink
fix(apis_entities,apis_relations): move TempTriple update code to signal
Browse files Browse the repository at this point in the history
Rather than hardcoding the TempTriple update in the merge method, we use
the `post_merge_with` signal to update the existing TempTriples

Closes: #1288
  • Loading branch information
b1rger committed Oct 15, 2024
1 parent 5d29433 commit ad25547
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 0 additions & 3 deletions apis_core/apis_entities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from apis_core.apis_entities import signals
from apis_core.apis_metainfo.models import RootObject, Uri
from apis_core.apis_relations.models import TempTriple

NEXT_PREV = getattr(settings, "APIS_NEXT_PREV", True)

Expand Down Expand Up @@ -122,8 +121,6 @@ def merge_with(self, entities):
if s not in sl:
getattr(self, f.name).add(s)
Uri.objects.filter(root_object=ent).update(root_object=self)
TempTriple.objects.filter(obj__id=ent.id).update(obj=self)
TempTriple.objects.filter(subj__id=ent.id).update(subj=self)

for ent in entities:
self.merge_fields(ent)
Expand Down
9 changes: 9 additions & 0 deletions apis_core/apis_relations/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.dispatch import receiver

from apis_core.apis_entities.signals import post_merge_with
from apis_core.apis_metainfo.models import RootObject
from apis_core.apis_metainfo.signals import post_duplicate
from apis_core.apis_relations.models import TempTriple
Expand All @@ -21,3 +22,11 @@ def copy_relations(sender, instance, duplicate, **kwargs):
newrel = rel.duplicate()
newrel.obj = duplicate
newrel.save()


@receiver(post_merge_with)
def merge_relations(sender, instance, entities, **kwargs):
for ent in entities:
logger.info(f"Merging relations from {ent!r} into {instance!r}")
TempTriple.objects.filter(obj__id=ent.id).update(obj=instance)
TempTriple.objects.filter(subj__id=ent.id).update(subj=instance)

0 comments on commit ad25547

Please sign in to comment.