[Django] #36566: Allow customization of returning_fields in bulk_create

6 views
Skip to first unread message

Django

unread,
Aug 21, 2025, 10:37:17 AM8/21/25
to django-...@googlegroups.com
#36566: Allow customization of returning_fields in bulk_create
------------------------------+-----------------------------------------
Reporter: Take Weiland | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+-----------------------------------------
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`.
--
Ticket URL: <https://code.djangoproject.com/ticket/36566>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 22, 2025, 3:31:34 AM8/22/25
to django-...@googlegroups.com
#36566: Allow customization of returning_fields in bulk_create
-------------------------------------+-------------------------------------
Reporter: Take Weiland | Owner: (none)
Type: New feature | Status: new
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => New feature

Comment:

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 [https://github.com/django
/new-features/issues ​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
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].

Thanks!
--
Ticket URL: <https://code.djangoproject.com/ticket/36566#comment:1>

Django

unread,
Aug 22, 2025, 3:31:43 AM8/22/25
to django-...@googlegroups.com
#36566: Allow customization of returning_fields in bulk_create
-------------------------------------+-------------------------------------
Reporter: Take Weiland | Owner: (none)
Type: New feature | Status: closed
Component: Database layer | Version: 5.2
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: new => closed

--
Ticket URL: <https://code.djangoproject.com/ticket/36566#comment:2>
Reply all
Reply to author
Forward
0 new messages