﻿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
31879	Changing a model formset's queryset has no effect when self.forms is accessed	kemar	nobody	"The Model formsets documentation [https://docs.djangoproject.com/en/3.1/topics/forms/modelforms/#changing-the-queryset suggests a way to override the default queryset]:

{{{
#!python
class BaseAuthorFormSet(BaseModelFormSet):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.queryset = Author.objects.filter(name__startswith='O')
}}}

However, accessing `self.forms` anywhere before `self.queryset` will trigger [https://github.com/django/django/blob/e74b3d724e5ddfef96d1d66bd1c58e7aae26fc85/django/forms/models.py#L629 get_queryset()] and silently populate `self._queryset` with all objects in the model so that the next `self.queryset` will have no effect:

{{{
#!python
class BaseAuthorFormSet(BaseModelFormSet):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        for form in self.forms:
            form.empty_permitted = False
        self.queryset = Author.objects.filter(name__startswith='O')  # No effect.
}}}

Can't tell if it's a bug or an intended behaviour?"	Uncategorized	closed	Forms	3.1	Normal	invalid	formsets		Unreviewed	0	0	0	0	0	0
