[Django] #26953: Should never get here. Please report a bug, including your model and model manager setup.

46 views
Skip to first unread message

Django

unread,
Jul 26, 2016, 9:45:17 AM7/26/16
to django-...@googlegroups.com
#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 (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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")),
)

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26953>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 26, 2016, 9:48:19 AM7/26/16
to django-...@googlegroups.com
#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 mikicz):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Adding {{{use_for_related_fields = True}}} to ExpenseManager fixed the
issue. But still...

--
Ticket URL: <https://code.djangoproject.com/ticket/26953#comment:1>

Django

unread,
Jul 27, 2016, 2:56:37 PM7/27/16
to django-...@googlegroups.com
#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:

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

New description:

}}}

{{{#!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

unread,
Jul 27, 2016, 3:09:49 PM7/27/16
to django-...@googlegroups.com
#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
-------------------------------------+-------------------------------------

Comment (by charettes):

Does the crash also happen if `managers.Manager` is used instead of
`managers.BaseManager`?

The later is not part of the public API and I would be tempted to close
this ticket as ''invalid'' if it's usage triggers the crash now that this
code path is gone in 1.10+.

--
Ticket URL: <https://code.djangoproject.com/ticket/26953#comment:3>

Django

unread,
Jul 27, 2016, 3:49:15 PM7/27/16
to django-...@googlegroups.com
#26953: Should never get here. Please report a bug, including your model and model
manager setup.
-------------------------------------+-------------------------------------
Reporter: mikicz | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: invalid
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):

* status: new => closed
* type: Uncategorized => Bug
* resolution: => invalid


Comment:

Using `Manager` rather than `BaseManager` doesn't crash on 1.9. Thanks
Simon.

--
Ticket URL: <https://code.djangoproject.com/ticket/26953#comment:4>

Django

unread,
Jul 27, 2016, 3:50:19 PM7/27/16
to django-...@googlegroups.com
#26953: Custom manager inheriting BaseManager.from_queryset() crashes with
AssertionError
-------------------------------------+-------------------------------------
Reporter: mikicz | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/26953#comment:5>

Reply all
Reply to author
Forward
0 new messages