﻿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
13677	ModelFormSet may query wrong database backend	Pierre Chifflier	Tobias Kunze	"When using a !ModelFormSet with a queryset using a DB different from the 'default' one, the validation of the fields fails.

debugging the code shows that the db used is the wrong one:
{{{
-> self.instance.clean_fields(exclude=exclude)
  /usr/lib/pymodules/python2.5/django/db/models/base.py(902)clean_fields()
-> setattr(self, f.attname, f.clean(raw_value, self))
  /usr/lib/pymodules/python2.5/django/db/models/fields/__init__.py(194)clean()
-> self.validate(value, model_instance)
  /usr/lib/pymodules/python2.5/django/db/models/fields/related.py(831)validate()
-> qs = self.rel.to._default_manager.filter(**{self.rel.field_name:value})
> /usr/lib/pymodules/python2.5/django/db/models/manager.py(141)filter()
-> return self.get_query_set().filter(*args, **kwargs)
(Pdb) p self.get_query_set().db
'default'
}}}

The !ModelFormSet was created by creating Form with a queryset:
{{{
def make_projecttask_formset(p, extra=0):
    class _ProjectTaskForm(forms.ModelForm):
        project = forms.ModelChoiceField(label=""Project"",
                queryset=Project.objects.using('otherdb').filter(project_id=p.project_id))
...
    return modelformset_factory(ew_projecttask, form=_ProjectTaskForm, extra=extra)
}}}

Expected behavior: used db should be the same as in the queryset

Note: it seems the problems is known (bug not fixed):
 * discussed in http://groups.google.com/group/django-developers/browse_thread/thread/22e52a2fd03eac82
 * someone proposed a patch at http://github.com/aparo/django/commit/edcdc1d9364224fcbc3b810b9d9fa19a10cd537c (only the fields/related part imho)"	Bug	assigned	Forms	dev	Normal			dgouldin@… rixx@…	Accepted	1	0	1	1	0	0
