#13677: wrong backend with multidb and modelformset
---------------------------+------------------------------------------------
Reporter: pollux | Owner: nobody
Status: new | Milestone:
Component: Uncategorized | Version: 1.2
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------+------------------------------------------------
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)
--
Ticket URL: <http://code.djangoproject.com/ticket/13677>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.