Django Signals Not Triggering After Bulk Create - Need Help Debugging
I'm working through a tutorial and I'm working on a Django application (version 4.0.1) where I'm using signals to perform some actions after a model instance is saved. Specifically, I'm trying to use the `post_save` signal to send a notification whenever a new user is created. However, I noticed that the signal is not being triggered when I perform a bulk create operation using `bulk_create()`. Hereβs the relevant part of my code: ```python from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver class User(models.Model): username = models.CharField(max_length=150) email = models.EmailField() @receiver(post_save, sender=User) def send_notification(instance, created, **kwargs): if created: print(f'Notification: New user {instance.username} created!') # Somewhere in my view users = [User(username='user1', email='user1@example.com'), User(username='user2', email='user2@example.com')] User.objects.bulk_create(users) ``` I expected the `send_notification` function to be called for each new user created, but it seems to be completely silent. Iβve verified that the users are indeed being added to the database, but the signal handler is not executing. I even tried using `post_save` in other areas of my code and it works perfectly with the regular `save()` method. Is this a known limitation of `bulk_create()`, or am I missing something? Any ideas on how to make my signal work with bulk operations? I'm eager to hear how I could achieve the same functionality without resorting to a manual workaround. Thanks in advance for your help! This is for a web app running on Debian.