django-model-utils icon indicating copy to clipboard operation
django-model-utils copied to clipboard

Can't use date_hierarchy for admin of model that uses InheritanceManager

Open sarahculkin opened this issue 8 years ago • 1 comments

Problem

If a model uses InheritanceManager and the model's admin has date_hierarchy, the following error appears when you navigate to the model's admin page:

TypeError at /admin/MyProject/mymodel/ _clone() got an unexpected keyword argument '_annotated'

This bug only appeared after upgrading to Django 2.0.

Environment

  • Django Model Utils version: 3.0.0
  • Django version: 2.0
  • Python version: 3.5.2

Code examples

models.py:

from django.db import models
from model_utils.managers import InheritanceManager

class MyModel(models.Model):
    objects = InheritanceManager()
    date_time_field = models.DateTimeField()

admin.py:

from django.contrib import admin
from .models import MyModel

@admin.register(MyModel):
class MyModelAdmin(admin.ModelAdmin):
    date_hierarchy = 'date_time_field'

sarahculkin avatar Dec 06 '17 11:12 sarahculkin

Pretty sure this doesn't have anything to do with the ModelAdmin portion of the examples above. I'm experiencing the same TypeError on a model that uses InheritanceManager, but without any ModelAdmin specified.

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/views/decorators/http.py", line 40, in inner
    return func(request, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/var/www/t4b-server/trivie/authentication.py", line 205, in do_authentication
    return f(*args, **kwargs)
  File "/var/www/t4b-server/management/views/dashboard.py", line 124, in difficult_questions
    .exclude(answered_count_calc__lte=3) \
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 843, in exclude
    return self._filter_or_exclude(True, *args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 850, in _filter_or_exclude
    clone = self._chain()
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 1156, in _chain
    obj = self._clone()
  File "/usr/local/lib/python3.5/dist-packages/model_utils/managers.py", line 100, in _clone
    return super(InheritanceQuerySetMixin, self)._clone(**kwargs)
TypeError: _clone() got an unexpected keyword argument '_annotated'

I plan on looking at this in more depth tomorrow. I'll report back with what I find.

digismack avatar Dec 07 '17 07:12 digismack