From d2b768f254749a9b8c1ecfc2487fef6eb39beb1e Mon Sep 17 00:00:00 2001 From: hancush Date: Tue, 3 Mar 2020 14:46:07 -0600 Subject: [PATCH 1/2] Save new objects after related objects are created --- pupa/importers/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pupa/importers/base.py b/pupa/importers/base.py index 1c074923..775e84f3 100644 --- a/pupa/importers/base.py +++ b/pupa/importers/base.py @@ -293,6 +293,10 @@ def import_item(self, data): self.model_class)) self._create_related(obj, related, self.related_models) + # Save object after related objects are created to allow for + # post-save signals that depend on related objects + obj.save() + if pupa_id: Identifier.objects.get_or_create(identifier=pupa_id, jurisdiction_id=self.jurisdiction_id, From 86006cf67546b0c9864425abc2e6efb130a5402e Mon Sep 17 00:00:00 2001 From: hancush Date: Tue, 3 Mar 2020 15:58:15 -0600 Subject: [PATCH 2/2] Send post_save signal explicitly after related objects created --- pupa/importers/base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pupa/importers/base.py b/pupa/importers/base.py index 775e84f3..0b46bab9 100644 --- a/pupa/importers/base.py +++ b/pupa/importers/base.py @@ -5,6 +5,7 @@ import logging from django.db.models import Q +from django.db.models.signals import post_save from django.contrib.contenttypes.models import ContentType from opencivicdata.legislative.models import LegislativeSession @@ -293,9 +294,9 @@ def import_item(self, data): self.model_class)) self._create_related(obj, related, self.related_models) - # Save object after related objects are created to allow for - # post-save signals that depend on related objects - obj.save() + # Fire post-save signal after related objects are created to allow + # for handlers make use of related objects + post_save.send(sender=self.model_class, instance=obj, created=True) if pupa_id: Identifier.objects.get_or_create(identifier=pupa_id,