[Django] #35014: update_or_create using update_fields opt out

43 views
Skip to first unread message

Django

unread,
Dec 5, 2023, 10:57:40 AM12/5/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-----------------------------------------+------------------------
Reporter: JordanHyatt | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 4.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 |
-----------------------------------------+------------------------
Prior to 4.2 update_or_create method did not use update_fields. That
means developer's could count on the model save method being run and all
fields being updated regardless of the defaults argument. After 4.2 only
those fields passed to default will be updated. This presents a major
breaking change especially for developers who rely heavily on save methods
to populate fields. I believe there should be a parameter added to
update_or_create that allows the user to opt out of using update_fields
during save.

--
Ticket URL: <https://code.djangoproject.com/ticket/35014>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 5, 2023, 2:23:40 PM12/5/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-------------------------------------+-------------------------------------
Reporter: Jordan Hyatt | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 4.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 Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix
* component: Uncategorized => Database layer (models, ORM)
* type: Uncategorized => Cleanup/optimization


Comment:

This is an intentional change mentioned in
[https://docs.djangoproject.com/en/stable/releases/4.2/#setting-update-
fields-in-model-save-may-now-be-required release notes].

> That means developer's could count on the model save method being run
and all fields being updated regardless of the defaults argument.

I'm not sure how you use this. Are you talking about database triggers
with some sophisticated behavior? If yes, then you can always pass all
fields in `update_fields` or use triggers on rows (not particular column)
update. I don't think it's worth additional complexity in Django itself.

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

Django

unread,
Dec 5, 2023, 4:00:35 PM12/5/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-------------------------------------+-------------------------------------
Reporter: Jordan Hyatt | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 4.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
-------------------------------------+-------------------------------------

Comment (by Jordan Hyatt):

I just thought it would be nice and simple to add a
"pass_update_fields=True" to update_or_create so that you can bypass the
new behavior implemented that can have a huge effect on previously written
code. You are right about catching the update_fields in the save, but
there is no way to know if the save was called by update_or_create or not.
What if sometimes I do want the update_fields to be used as is, just not
when update_or_create was the source?

--
Ticket URL: <https://code.djangoproject.com/ticket/35014#comment:2>

Django

unread,
Dec 5, 2023, 4:10:30 PM12/5/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-------------------------------------+-------------------------------------
Reporter: Jordan Hyatt | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 4.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
-------------------------------------+-------------------------------------

Comment (by Jordan Hyatt):

Also, in general, I don't think its a bad idea to have a little control
over the way that update_or_create calls the save method. It's not overly
complicated to give a little flexibility in that regard

--
Ticket URL: <https://code.djangoproject.com/ticket/35014#comment:3>

Django

unread,
Dec 5, 2023, 4:21:01 PM12/5/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-------------------------------------+-------------------------------------
Reporter: Jordan Hyatt | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 4.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 Jordan Hyatt):

* Attachment "update_or_create.PNG" added.

Suggested Changes

Django

unread,
Dec 5, 2023, 5:50:56 PM12/5/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-------------------------------------+-------------------------------------
Reporter: Jordan Hyatt | Owner: nobody
Type: | Status: new

Cleanup/optimization |
Component: Database layer | Version: 4.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 Jordan Hyatt):

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


--
Ticket URL: <https://code.djangoproject.com/ticket/35014#comment:4>

Django

unread,
Dec 5, 2023, 11:35:17 PM12/5/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-------------------------------------+-------------------------------------
Reporter: Jordan Hyatt | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: 4.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 Mariusz Felisiak):

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


Comment:

I appreciate you'd like to reopen the ticket, but please
[https://docs.djangoproject.com/en/stable/internals/contributing/triaging-
tickets/#closing-tickets follow the triaging guidelines with regards to
wontfix tickets] and take this to DevelopersMailingList (or
[https://forum.djangoproject.com/ Django Forum]) , where you'll reach a
wider audience and see what other think.

> But wouldn't it be kind of neat if update_or_create could pass along
additional kwargs to your custom save method?

We don't add new options if it's not something useful for many folks.

> I know I have plenty of use cases for that.

You didn't not present any specifics. Please be prepared to share concrete
example in a forum/mailing list thread, if you will decide to start a
discussion.

--
Ticket URL: <https://code.djangoproject.com/ticket/35014#comment:5>

Django

unread,
Dec 6, 2023, 8:18:30 AM12/6/23
to django-...@googlegroups.com
#35014: update_or_create using update_fields opt out
-------------------------------------+-------------------------------------
Reporter: Jordan Hyatt | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Database layer | Version: 4.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
-------------------------------------+-------------------------------------

Comment (by Jordan Hyatt):

I have opened a forum topic where I posted a concrete use case.
https://forum.djangoproject.com/t/update-or-create-behavior/25944

--
Ticket URL: <https://code.djangoproject.com/ticket/35014#comment:6>

Reply all
Reply to author
Forward
0 new messages