Opened 8 years ago

Last modified 8 years ago

#26953 closed Bug

Should never get here. Please report a bug, including your model and model manager setup. — at Initial Version

Reported by: Mikuláš Poul Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords:
Cc: Loic Bistuer Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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")),
        )

Change History (0)

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