﻿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
25227	Promote modifying form.instance directly instead of using ModelForm.save(commit=False)	Javier Candeira	Javier Candeira	"While doing the djangogirls tutorial, I noticed that ModelForm.save(commit=False) is given to newcomers as a reasonable way to acquire a form's populated model. This is an antipattern for several reasons:

  - It's counterintuitive. To a newcomer, it's the same as ``save(save=no)``. 
  - It's a leaky abstraction. Understanding it requires understanding that the `save()` method does two things: a) return the model, and b) save it to the database.
  - It doesn't name its effect or return well.

The first two issues are addressed in the current patch. About the third, the mailing list discussion convinced me to avoid the `.get_updated_model()` name. Instead, `apply()` was used.

Changes:

 - Implement `ModelForm.apply()` as alternative to `.save(commit=False)`
 - Implement `FormSet.apply()` as alternative to `.save(commit=False)`
 - Refactor `ModelForm.save()` and `FormSet.save()` to allow the above.
 - New tests have been added for the new methods in different contexts (from a ModelForm, from a FormSet, etc).
 - documentation has also been modified to showcase the new methods.

Notes:

Uses of either `.save(commit=False)` in the codebase have been left alone wherever it was used for its side effects (the return value was not used).

The Djangogirls tutorial has a PR that depends on the changes in the present one:

https://github.com/DjangoGirls/tutorial/pull/450"	Cleanup/optimization	closed	Documentation	dev	Normal	wontfix			Accepted	0	0	0	0	0	0
