}}}
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.
* 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>
* 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>
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>
* 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>
--
Ticket URL: <https://code.djangoproject.com/ticket/26953#comment:5>