django-autoslug icon indicating copy to clipboard operation
django-autoslug copied to clipboard

Autoslug does not create unique slugs with `bulk_create`

Open ghost opened this issue 8 years ago • 1 comments
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

ghost avatar Aug 18 '17 13:08 ghost

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.

jeffcjohnson avatar Oct 14 '17 13:10 jeffcjohnson