﻿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
32937	Form.get_initial_for_field() can return different values if called more than once	Chris Jerdonek	nobody	"Currently, [https://github.com/django/django/blob/304f6ff46a9d78aab0213b599356d3c7875b0bb9/django/forms/forms.py#L470-L478 Form.get_initial_for_field()] is [https://docs.djangoproject.com/en/3.2/ref/forms/api/#django.forms.Form.get_initial_for_field documented] as a way to retrieve the initial data for a form field. However, it has the problem that it doesn't cache its return values, like [https://github.com/django/django/blob/304f6ff46a9d78aab0213b599356d3c7875b0bb9/django/forms/boundfield.py#L229-L237 BoundField.initial] does, which can lead to buggy behavior e.g. in the case of callables that return different values each time.

One way to fix this would be for `get_initial_for_field()` to get its value from `BoundField` when it needs to fall back to the field, which can then cache it (similar to how `BoundField.initial` caches its return value). The downside of this is that it adds another layer of indirection, as `BoundField.initial` is already going to `Form.get_initial_for_field()` for its value. Another option might be to deprecate `get_initial_for_field()`, as I'm not sure if it provides any benefit that an API on `BoundField` couldn't better provide.

See also #32933.
"	Uncategorized	closed	Forms	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
