from django.db import transaction from django.db.models.signals import post_save from django.dispatch import receiver from labs.models import CertificateIssuance @receiver(post_save, sender=CertificateIssuance) def sync_certificate_info_to_hubspot_on_certificate_issuance_created( sender, instance, created, **kwargs ): if created: from labs.tasks import sync_certificate_info_to_hubspot_task def queue_hubspot_sync(): sync_certificate_info_to_hubspot_task.delay(instance.id) transaction.on_commit(queue_hubspot_sync)