Opened 4 years ago

Closed 4 years ago

#31957 closed Bug (invalid)

ModelAdmin method save_form not documented but being called multiple times

Reported by: Ivan Gonzalez Owned by: nobody
Component: contrib.admin Version: 3.1
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 (last modified by Ivan Gonzalez)

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

As you can search in the docs ( 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 method and ModelAdmin.save_model calls the 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 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.

Change History (4)

comment:1 by Ivan Gonzalez, 4 years ago

Description: modified (diff)

comment:2 by Ivan Gonzalez, 4 years ago

Description: modified (diff)

comment:3 by Ivan Gonzalez, 4 years ago

Type: Cleanup/optimizationBug

comment:4 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

ModelAdmin.save_model() calls 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.

Note: See TracTickets for help on using tickets.
Back to Top