Opened 5 years ago

Last modified 4 years ago

#13677 new Bug

wrong backend with multidb and modelformset

Reported by: pollux Owned by: dgouldin
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords:
Cc: dgouldin@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

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):

Attachments (1)

13677.diff (3.1 KB) - added by dgouldin 5 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by russellm

  • Component changed from Uncategorized to Database layer (models, ORM)
  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by dgouldin

  • Cc dgouldin@… added
  • Owner changed from nobody to dgouldin

Changed 5 years ago by dgouldin

comment:3 Changed 5 years ago by dgouldin

  • Has patch set

comment:4 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to Bug

comment:5 Changed 4 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

13677.diff fails to apply cleanly on to trunk

comment:6 Changed 4 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:11 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

Note: See TracTickets for help on using tickets.
Back to Top