Opened 2 weeks ago

Closed 2 weeks ago

#36566 closed New feature (wontfix)

Allow customization of returning_fields in bulk_create

Reported by: Take Weiland Owned by:
Component: Database layer (models, ORM) Version: 5.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On databases that support INSERT ... RETURNING (all but MySQL), bulk_create will use it to retrieve the values of generated columns of the inserted rows. "generated columns" currently being AutoField and GeneratedField. These are marked using db_returning = True.

This is sufficient for standard uses of bulk_create. However bulk_create supports a parameter named update_conflicts. In case update_conflicts Django should use INSERT ... RETURNING for at least the primary key, regardless of whether it is an AutoField or not. This way the objects returned by bulk_create will have the correct primary key set, regardless of whether they were inserted or updated.

I would also propose adding another parameter to bulk_create (e.g. returning_fields) to let users specify additional fields Django should fetch using INSERT ... RETURNING. This way users can specify additional fields that they need to be up to date in the returned objects when using update_conflicts.

Change History (2)

comment:1 by Sarah Boyce, 2 weeks ago

Component: UncategorizedDatabase layer (models, ORM)
Type: UncategorizedNew feature

Hi

This report appears to be about requesting a new feature for Django.

Thank you for your suggestion! When suggesting a new feature for Django, the feature idea should first be proposed and discussed with the community. To do that, please raise this on the new feature tracker.

I'll close the ticket for now, but if the community agrees with the proposal, please return to this ticket and reference the forum discussion so we can re-open it. For more information, please refer to the documented guidelines for requesting features.

Thanks!

comment:2 by Sarah Boyce, 2 weeks ago

Resolution: wontfix
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top