#26953: Should never get here. Please report a bug, including your model and 
model
manager setup.
-------------------------------------+-------------------------------------
     Reporter:  mikicz               |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by timgraham):

 * cc: loic (added)


Old description:

> The unthinkable happened!
> {{{
> Traceback (most recent call last):
>   File "manage.py", line 14, in <module>
>     execute_from_command_line(sys.argv)
>   File "{...}/local/lib/python2.7/site-
> packages/django/core/management/__init__.py", line 350, in
> execute_from_command_line
>     utility.execute()
>   File "{...}/local/lib/python2.7/site-
> packages/django/core/management/__init__.py", line 324, in execute
>     django.setup()
>   File "{...}/local/lib/python2.7/site-packages/django/__init__.py", line
> 18, in setup
>     apps.populate(settings.INSTALLED_APPS)
>   File "{...}/local/lib/python2.7/site-packages/django/apps/registry.py",
> line 108, in populate
>     app_config.import_models(all_models)
>   File "{...}/local/lib/python2.7/site-packages/django/apps/config.py",
> line 202, in import_models
>     self.models_module = import_module(models_module_name)
>   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in
> import_module
>     __import__(name)
>   File "{...}/budgetter-app/apps/expense/models.py", line 29, in <module>
>     class Expense(models.Model):
>   File "{...}/local/lib/python2.7/site-
> packages/django/db/models/base.py", line 283, in __new__
>     new_class._prepare()
>   File "{...}/local/lib/python2.7/site-
> packages/django/db/models/base.py", line 332, in _prepare
>     ensure_default_manager(cls)
>   File "{...}/local/lib/python2.7/site-
> packages/django/db/models/manager.py", line 45, in ensure_default_manager
>     "Should never get here. Please report a bug, including your "
> AssertionError: Should never get here. Please report a bug, including
> your model and model manager setup.
>
> }}}
>
> My model and manager setup
>
> {{{
>
> # encoding=utf-8
> from __future__ import unicode_literals, print_function
>
> from django.db import models
> from django.db.models.manager import BaseManager
> from django.db.models.query import QuerySet
> from django.utils.translation import ugettext_lazy as _
> from django.core.exceptions import ValidationError
>

> class ExpenseQuerySet(QuerySet):
>
>     def all(self):
>         return super(ExpenseQuerySet, self).all().filter(deleted=False)
>
>     def delete(self):
>         return self.update(deleted=True)
>

> class ExpenseManager(BaseManager.from_queryset(ExpenseQuerySet)):
>     pass
>

> def validate_period(value):
>     if value not in [x[0] for x in Expense.PERIODS]:
>         raise ValidationError(_("Period not in choices."))
>

> class Expense(models.Model):
>
>     PERIODS = (
>         ('monthly', _("Monthly")),
>         ('quarterly', _("Quarterly")),
>         ('yearly', _("Monthly"))
>     )
>
>     period = models.CharField(verbose_name=_("Period"), choices=PERIODS,
> max_length=10,
>                               validators=[validate_period])
>
>     amount = models.FloatField(verbose_name=_("Amount"))
>     description = models.CharField(max_length=255,
> verbose_name=_("Description"))
>     valid_from = models.DateField(verbose_name=_("Valid from"),
> null=True)
>     valid_to = models.DateField(verbose_name=_("Valid to"), null=True)
>
>     deleted = models.BooleanField(default=False,
> verbose_name=_("Deleted"))
>
>     objects = ExpenseManager()
>
>     def delete(self, **kwargs):
>         Expense.objects.filter(pk=self.pk).update(deleted=True)
>
>     class Meta:
>         verbose_name = _("Expense")
>         verbose_name_plural = _("Expenses")
>         permissions = (
>             ('list_expenses', _("Can list expenses")),
>         )
>
> }}}

New description:

 The unthinkable happened!
 {{{
 Traceback (most recent call last):
   File "manage.py", line 14, in <module>
     execute_from_command_line(sys.argv)
   File "{...}/local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 350, in
 execute_from_command_line
     utility.execute()
   File "{...}/local/lib/python2.7/site-
 packages/django/core/management/__init__.py", line 324, in execute
     django.setup()
   File "{...}/local/lib/python2.7/site-packages/django/__init__.py", line
 18, in setup
     apps.populate(settings.INSTALLED_APPS)
   File "{...}/local/lib/python2.7/site-packages/django/apps/registry.py",
 line 108, in populate
     app_config.import_models(all_models)
   File "{...}/local/lib/python2.7/site-packages/django/apps/config.py",
 line 202, in import_models
     self.models_module = import_module(models_module_name)
   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in
 import_module
     __import__(name)
   File "{...}/budgetter-app/apps/expense/models.py", line 29, in <module>
     class Expense(models.Model):
   File "{...}/local/lib/python2.7/site-packages/django/db/models/base.py",
 line 283, in __new__
     new_class._prepare()
   File "{...}/local/lib/python2.7/site-packages/django/db/models/base.py",
 line 332, in _prepare
     ensure_default_manager(cls)
   File "{...}/local/lib/python2.7/site-
 packages/django/db/models/manager.py", line 45, in ensure_default_manager
     "Should never get here. Please report a bug, including your "
 AssertionError: Should never get here. Please report a bug, including your
 model and model manager setup.

 }}}

 My model and manager setup

 {{{#!python
 from django.db import models
 from django.db.models.manager import BaseManager
 from django.db.models.query import QuerySet

 class ExpenseQuerySet(QuerySet):
    pass

 class ExpenseManager(BaseManager.from_queryset(ExpenseQuerySet)):
     pass

 class Expense(models.Model):
     objects = ExpenseManager()
 }}}

--

Comment:

 There's no crash in Django 1.10 as of
 ed0ff913c648b16c4471fc9a9441d1ee48cb5420, however, I'm not certain about
 the correct resolution of this ticket. For example, should we add an
 additional test for this case?

 I edited the description to leave only the minimal code necessary to
 reproduce the issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/26953#comment:2>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.7214b865a772b16b0456fc7a6380ad91%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to