Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoslug does not create unique slugs with bulk_create #28

Open
ghost opened this issue Aug 18, 2017 · 1 comment
Open

Autoslug does not create unique slugs with bulk_create #28

ghost opened this issue Aug 18, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 18, 2017

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
@jeffcjohnson
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant