django-autoslug
django-autoslug copied to clipboard
Autoslug does not create unique slugs with `bulk_create`
trafficstars
Add this test to AutoSlugFieldTestCase and see it raise an exception:
def test_uniqueness_slug_with_bulk_create(self):
ModelWithUniqueSlug.objects.bulk_create([
ModelWithUniqueSlug(name='test'),
ModelWithUniqueSlug(name='test'),
])
a, b = list(ModelWithUniqueSlug.objects.all())
assert a.slug != b.slug
Since the field is updated by pre_save and post_save signals I don't think bulk_create is expected to worth with auto slug. The same is true for update.
https://docs.djangoproject.com/en/1.11/ref/models/querysets/#bulk-create
The model’s save() method will not be called, and the pre_save and post_save signals will not be sent.
A warning in the auto slug documentation might be warranted.