However, the ModelForm initialisation code is using the default manager
instead when initialising the fields during loading (see
django/db/models/fields/related.py:1749)
So, if you have a model that is using a custom default manager, the
modelform attempts to use this manager instead leading to some very
unexpected side effects particularly when running the server and loading
up the code initially.
--
Ticket URL: <https://code.djangoproject.com/ticket/23710>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
The default manager is the first manager defined, not necessarily a
"plain" manager, right?
https://github.com/django/django/blob/d49183e4bed8ecf21faad44372ea15ff00f781b5/django/db/models/manager.py#L127-129
--
Ticket URL: <https://code.djangoproject.com/ticket/23710#comment:1>
* component: Uncategorized => Database layer (models, ORM)
Comment:
Collin, yes that's what's documented in the
[https://docs.djangoproject.com/en/1.7/topics/db/managers/#default-
managers default managers] docs.
I am not sure about this. The behavior doesn't seem to be well defined as
I couldn't find any documentation about this and no tests fail if I make
this change (please correct me if this is the wrong line; this is the
closest line I could find on stable/1.7.x to the one you referenced):
{{{
#!diff
diff --git a/django/db/models/fields/related.py
b/django/db/models/fields/related.py
index d87a922..0b4d726 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -1759,7 +1759,7 @@ class ForeignKey(ForeignObject):
(self.name, self.rel.to))
defaults = {
'form_class': forms.ModelChoiceField,
- 'queryset': self.rel.to._default_manager.using(db),
+ 'queryset': self.rel.to._base_manager.using(db),
'to_field_name': self.rel.field_name,
}
defaults.update(kwargs)
}}}
On the other hand, I could see the current behavior as expected and
changing it could cause problems for people relying on it.
--
Ticket URL: <https://code.djangoproject.com/ticket/23710#comment:2>
* status: new => closed
* resolution: => needsinfo
Comment:
Lacking any follow-up from the reporter, I'm going to close as "needs
info". Feel free to reopen if you can describe more about the problem
here.
--
Ticket URL: <https://code.djangoproject.com/ticket/23710#comment:3>