﻿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
29474	Simply BaseInlineFormset.save_new() with call to super()	ljsjl	nobody	"Looking at save_new() in BaseInlineFormset it seems it can be replaced with e.g.
{{{
--- a/django/forms/models.py
+++ b/django/forms/models.py
@@ -940,17 +940,7 @@ class BaseInlineFormSet(BaseModelFormSet):
         # form (it may have been saved after the formset was originally
         # instantiated).
         setattr(form.instance, self.fk.name, self.instance)
-        # Use commit=False so we can assign the parent key afterwards, then
-        # save the object.
-        obj = form.save(commit=False)
-        pk_value = getattr(self.instance, self.fk.remote_field.field_name)
-        setattr(obj, self.fk.get_attname(), getattr(pk_value, 'pk', pk_value))
-        if commit:
-            obj.save()
-        # form.save_m2m() can be called via the formset later on if commit=False
-        if commit and hasattr(form, 'save_m2m'):
-            form.save_m2m()
-        return obj
+        return super().save_new(form, commit=commit)
 
     def add_fields(self, form, index):
         super().add_fields(form, index)
}}}

This passes the existing test suite so suggests yes, or that the test suite is missing important cases.

From my shaky grasp of model field internals the extra lines set the value of the field attname (e.g. user_id) attribute, but this is already set by the earlier setattr call updating form.instance. I feel like I'm missing something here but it seems to work so...?

Cheers
LJS"	Cleanup/optimization	closed	Forms	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
