﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11830	save_model in ModelAdmin and inline model formsets	Nils Fredrik Gjerull	nobody	"I tried to use the {{{save_model}}} in {{{ModelAdmin}}} to add and remove some related objects for the saved instance. But because {{{save_formset}}} is called after {{{save_model}}} a {{{ValidationError}}} is emitted. This happens because my code removes a related object expected by a {{{BaseInlineFormSet}}}. The reason I use {{{save_model}}} and not the save method on the model is because I need access to the request object. If, however, I did this in the {{{save}}} method of the model the error will still be the same. {{{save_formset}}} is called after {{{save_model}}} which call the {{{save}}} method on the model instance. If you remove a related object to a model instance expected by one of {{{ModelAdmin}}}'s related formsets you get an error.

I have supplied a patch containing a test that trigger this error. I have also included a rater naive fix, which simply ignores related objects triggering {{{ValidationError}}} in {{{save_existing_object}}}. The exception is emitted in a context where it is not caught by the form handling code."	Bug	closed	contrib.admin	dev	Normal	needsinfo	save_model save		Accepted	1	0	0	1	0	0
