During import, post_save receiver is called twice
See original GitHub issueI asked this question on SO but have had no reply so I thought I raise an issue: https://stackoverflow.com/questions/60124600/django-import-export-post-save-called-twice
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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:9 (1 by maintainers)
Top GitHub Comments
I have described detailed issue in pr, why it happens : https://github.com/django-import-export/django-import-export/pull/1176 Use this fix, inherit below class
i am having the same issue, I am using django-elasticsearch-dsl to index new created objects into elasticsearch, but when I use django-import-export the save post_save signal is triggering twice, so it indexes the imported row twice. Is there a way to disable signals if the import is a dry-run?