I created a custom user subclassed from AbstractUser and a post_save signal and a receiver that prints the new user's id.
@receiver(post_save, sender=CustomUser, dispatch_uid='members.models.customuser.post_save')
def post_save_custom_user(sender, instance=None, created=False, **kwargs):
if not created:
return
print('post_save_custom_user: {}'.format(instance.id))
When I create a new user via the admin interface the receiver is called once. When I import a user using django-import-export
the receiver is called twice: once after the initial Submit
of the import file and then again after the Confirm Import
. Browsing through the code I see it creates the user in dry_run, rolls back the transaction and creates it again. But how can I tell in my receiver if it's a dry run or not?
I am using Python 3.6, Django 3.0.3, django-import-export 2.0.1
transaction.on_commit
. you can importtransaction
fromdjango.db
– Dapplegraytransaction.on_commit(lambda: print('post_save_custom_user: {}'.format(instance.id)))
but it still gets called twice. – Supervise