Changes between Initial Version and Version 3 of Ticket #17038
- Timestamp:
- Nov 26, 2011, 6:06:23 AM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #17038
- Property Summary Use of _default_manager instead of _base_manager in ForeignKey form field validation → Use of _default_manager instead of _base_manager in ForeignKey ModelForm field validation
- Property Component Forms → Database layer (models, ORM)
- Property Easy pickings unset
-
Ticket #17038 – Description
initial v3 1 1 I'm not absolutely convinced this is a bug, but it is causing me grief and appears to be a bug when considered against [https://docs.djangoproject.com/en/dev/topics/db/managers/#controlling-automatic-manager-types Django's documented methodology with respect to "plain" manager usage vs. default manager usage]. 2 2 3 The bug I am referring to is located in: 4 5 django/db/models/fields/related.py , line 850 6 (version 1.3.1) 3 The bug I am referring to is located in django/db/models/fields/related.py , line 850, (version 1.3.1) 7 4 8 5 This is in the "validate" method of ForeignKey. Specifically, the problematic code is: 9 6 7 {{{ 10 8 qs = self.rel.to.'''_default_manager'''.using(using).filter( 11 9 *''*''{self.rel.field_name: value} … … 15 13 raise exceptions.ValidationError(self.error_messages['invalid'] % { 16 14 'model': self.rel.to._meta.verbose_name, 'pk': value}) 15 }} 17 16 18 To me, this should be using _base_manager instead of _default_managerin order to be consistent with Django's stated plain vs. default "automatic manager" paradigm for foreign key lookups.17 To me, this should be using `_base_manager` instead of `_default_manager` in order to be consistent with Django's stated plain vs. default "automatic manager" paradigm for foreign key lookups. 19 18 20 19 The specific problem I am running into is that my default manager's get_queryset method filters out a significant number of records (archived records), but I also have a secondary manager which includes them. In my form, I have an option to load a ModelChoiceField using the queryset from the secondary manager, including the archived records. However, validation for my form fails if a archived record is selected, since the above code looks to the default manager (which excludes all archived records) for validation instead of a "plain" manager.