Django Signals Not Firing on Bulk Create with Django 4.1
Could someone explain I've hit a wall trying to I've looked through the documentation and I'm still confused about I'm maintaining legacy code that I'm experiencing an issue where my Django signals are not firing as expected when using the `bulk_create` method. I have defined a signal to perform some actions after a model instance is created, but it seems that the signal is not triggered during a bulk creation operation. Here's the setup: I have a simple model `UserProfile` and a corresponding signal handler that logs when a new profile is created: ```python from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver class UserProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) bio = models.TextField() @receiver(post_save, sender=UserProfile) def user_profile_created(sender, instance, created, **kwargs): if created: print(f'UserProfile created for {instance.user.username}') ``` In my view, I am trying to create multiple user profiles in one go: ```python from django.shortcuts import render from .models import UserProfile users_data = [ {'user': user1, 'bio': 'Bio for user 1'}, {'user': user2, 'bio': 'Bio for user 2'}, ] profiles = [UserProfile(**data) for data in users_data] UserProfile.objects.bulk_create(profiles) ``` When I run this code, the `user_profile_created` signal is not triggered, and I don't see any of the print statements in my console. I know that `bulk_create` is optimized for performance and does not call the `save()` method on each instance, but I would expect that signals should still work in this case. Is there any way to make this work, or is there an alternative approach I should consider for handling post-creation logic in bulk operations? Also, if I switch to using a loop with `save()` instead of `bulk_create`, I encounter performance issues due to the number of operations being performed. Any suggestions would be greatly appreciated. Am I missing something obvious? Has anyone else encountered this? This issue appeared after updating to Python 3.11. I'm developing on macOS with Python. What would be the recommended way to handle this?