Skip to content

bulk_create_with_history acts incorrectly with duplicate objects #1032

Closed
@WestonChan

Description

@WestonChan

Describe the bug
When using bulk_create_with_history, if there is an item that is a duplicate (either created earlier in the same batch or already existing in the database) the returned object includes both the newly created and the existing duplicated object.
In addition, history will be generated for both items, even though only the newer item should have generated history. This will happen multiple times if the duplicates are created in the same batch.

In summary:

If a duplicate item already exists in the database:

  • All duplicate items will be returned
  • History will be generated for all duplicate items

To Reproduce

  1. Use a database which doesn't return ids
  2. Save an object to the database
  3. Create duplicate object(s) using bulk_create_with_history
  4. Inspect returned result and historical entry

Expected behavior

  • Only items that were created should be returned
  • Duplicated objects that were not created should not be returned
  • History should be generated only for objects that were created

Environment:

  • Django Simple History Version: 3.0.0
  • Django Version: 3.2.15
  • Database Version: MySQL 8.0.29

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions