[Django] #31957: ModelAdmin method save_form not documented but being called multiple times

19 views
Skip to first unread message

Django

unread,
Aug 28, 2020, 1:11:22 AM8/28/20
to django-...@googlegroups.com
#31957: ModelAdmin method save_form not documented but being called multiple times
------------------------------------------------+------------------------
Reporter: scratchmex | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 3.1
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 |
------------------------------------------------+------------------------
I take the opportunity to say this is my first ticket (issue) posted for
Django.

As you can search in the docs
(https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-
options). There is no documentation about the `ModelAdmin.save_form`
method but is being called multiple times (lines 1763 and 1575 in
`django.contrib.admin.options`).

On the other hand, `ModelAdmin.save_form` calls the `form.save` method and
`ModelAdmin.save_model` calls the `obj.save` method, but
`ModelAdmin.save_form` and `ModelAdmin.save_model` are called in the same
flow (lines 1763,1764 and 1575,1580 in `django.contrib.admin.options`),
i.e., both can be called in serial leading to multiple saves of the same
object. Maybe a better documentation of that, a suggestion of which to
use, and if it's possible an optimization of those calls would be great.

I'm all ears to your comments.

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

Django

unread,
Aug 28, 2020, 1:16:15 AM8/28/20
to django-...@googlegroups.com
#31957: ModelAdmin method save_form not documented but being called multiple times
-------------------------------------+-------------------------------------
Reporter: scratchmex | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.1
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
-------------------------------------+-------------------------------------
Description changed by scratchmex:

Old description:

> I take the opportunity to say this is my first ticket (issue) posted for
> Django.
>
> As you can search in the docs
> (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-
> options). There is no documentation about the `ModelAdmin.save_form`
> method but is being called multiple times (lines 1763 and 1575 in
> `django.contrib.admin.options`).
>
> On the other hand, `ModelAdmin.save_form` calls the `form.save` method
> and `ModelAdmin.save_model` calls the `obj.save` method, but
> `ModelAdmin.save_form` and `ModelAdmin.save_model` are called in the same
> flow (lines 1763,1764 and 1575,1580 in `django.contrib.admin.options`),
> i.e., both can be called in serial leading to multiple saves of the same
> object. Maybe a better documentation of that, a suggestion of which to
> use, and if it's possible an optimization of those calls would be great.
>
> I'm all ears to your comments.

New description:

I take the opportunity to say this is my first ticket (issue) posted for
Django.

As you can search in the docs
(https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-
options). There is no documentation about the `ModelAdmin.save_form`
method but is being called multiple times (lines 1763 and 1575 in
`django.contrib.admin.options`).

On the other hand, `ModelAdmin.save_form` calls the `form.save` method and
`ModelAdmin.save_model` calls the `obj.save` method, but
`ModelAdmin.save_form` and `ModelAdmin.save_model` are called in the same
flow (lines 1763,1764 and 1575,1580 in `django.contrib.admin.options`),
i.e., both can be called in serial leading to multiple saves of the same

object. This is specially important when using `signals` because two calls
to save may trigger duplicate signals. Maybe a better documentation of


that, a suggestion of which to use, and if it's possible an optimization
of those calls would be great.

I'm all ears to your comments.

--

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

Django

unread,
Aug 28, 2020, 1:16:59 AM8/28/20
to django-...@googlegroups.com
#31957: ModelAdmin method save_form not documented but being called multiple times
-------------------------------------+-------------------------------------
Reporter: scratchmex | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 3.1
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
-------------------------------------+-------------------------------------
Description changed by scratchmex:

Old description:

> I take the opportunity to say this is my first ticket (issue) posted for


> Django.
>
> As you can search in the docs
> (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-
> options). There is no documentation about the `ModelAdmin.save_form`
> method but is being called multiple times (lines 1763 and 1575 in
> `django.contrib.admin.options`).
>
> On the other hand, `ModelAdmin.save_form` calls the `form.save` method
> and `ModelAdmin.save_model` calls the `obj.save` method, but
> `ModelAdmin.save_form` and `ModelAdmin.save_model` are called in the same
> flow (lines 1763,1764 and 1575,1580 in `django.contrib.admin.options`),
> i.e., both can be called in serial leading to multiple saves of the same

> object. This is specially important when using `signals` because two

> calls to save may trigger duplicate signals. Maybe a better documentation


> of that, a suggestion of which to use, and if it's possible an
> optimization of those calls would be great.
>
> I'm all ears to your comments.

New description:

I take the opportunity to say this is my first ticket (issue) posted for
Django.

As you can search in the docs
(https://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-
options). There is no documentation about the `ModelAdmin.save_form`
method but is being called multiple times (lines 1763 and 1575 in
`django.contrib.admin.options`).

On the other hand, `ModelAdmin.save_form` calls the `form.save` method and
`ModelAdmin.save_model` calls the `obj.save` method, but
`ModelAdmin.save_form` and `ModelAdmin.save_model` are called in the same
flow (lines 1763,1764 and 1575,1580 in `django.contrib.admin.options`),
i.e., both can be called in serial leading to multiple saves of the same

object. This is specially important when using `signals` because two calls

to `obj.save` may trigger duplicate signals when listening to `post_save`,
for example. Maybe a better documentation of that, a suggestion of which


to use, and if it's possible an optimization of those calls would be
great.

I'm all ears to your comments.

--

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

Django

unread,
Aug 28, 2020, 1:17:55 AM8/28/20
to django-...@googlegroups.com
#31957: ModelAdmin method save_form not documented but being called multiple times
-------------------------------+--------------------------------------
Reporter: scratchmex | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.1
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 scratchmex):

* type: Cleanup/optimization => Bug


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

Django

unread,
Aug 31, 2020, 4:37:45 AM8/31/20
to django-...@googlegroups.com
#31957: ModelAdmin method save_form not documented but being called multiple times
-------------------------------+--------------------------------------
Reporter: Ivan Gonzalez | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.1
Severity: Normal | Resolution: invalid

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 felixxm):

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


Comment:

`ModelAdmin.save_model()` calls `form.save(commit=False)` that doesn't
call `save()` on instance so it will not trigger the `post_save` signal. I
don't see any issue in the current flow.

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

Reply all
Reply to author
Forward
0 new messages