question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Django 1.10 default manager not MultilingualManager for model inheriting abstract class with a manager defined on objects (leading to AttributeError: 'QuerySet' object has no attribute 'rewrite')

See original GitHub issue

Whilst upgrading my application to Django 1.10 I came across the following issue where the default manager for a Model Translation registered model didn’t get dynamically set to modeltranslation.manager.MultilingualManager.

This resulted in an exception being thrown in update_translation_fields.py L32

AttributeError: 'QuerySet' object has no attribute 'rewrite'

A similar issue was resolved in #123 but it seems something in the internal changes in Django 1.10 has resurfaced it in the particular scenario I have (not one covered by #381).

I haven’t yet identified what the changes are that cause it but I’ve narrowed the scenario down to one in which a model inherits from an abstract model that explicitly sets a manager via the objects attribute. In this case the resulting _default_manager is that set on objects rather than modeltranslation.manager.MultilingualManager.

The simplest example I can boil it down to is this:

# models.py

class FooAbstract(models.Model):
    class Meta:
        abstract = True

class Foo(FooAbstract):
    name = models.CharField(blank=True, max_length=1)

class Bar(models.Model):
    objects = models.Manager()
    name = models.CharField(blank=True, max_length=1)

class BazAbstract(models.Model):
    objects = models.Manager()
    class Meta:
        abstract = True

class Baz(BazAbstract):
    name = models.CharField(blank=True, max_length=1)


# translations.py

@register(Foo)
class FooTranslationOptions(TranslationOptions):
    fields = ('name',)

@register(Bar)
class BarTranslationOptions(TranslationOptions):
    fields = ('name',)

@register(Baz)
class BazTranslationOptions(TranslationOptions):
    fields = ('name',)


# shell

from modeltranslation.translator import translator
models = translator.get_registered_models(abstract=False)
for model in models:
    print(model.__name__, type(model._default_manager))

# Django 1.9 output:

Foo <class 'modeltranslation.manager.MultilingualManager'>
Bar <class 'modeltranslation.manager.MultilingualManager'>
Baz <class 'modeltranslation.manager.MultilingualManager'>

# Django 1.10 output:

Foo <class 'modeltranslation.manager.MultilingualManager'>
Bar <class 'modeltranslation.manager.MultilingualManager'>
Baz <class 'django.db.models.manager.Manager'>

I don’t have a solution yet but thought I’d submit it as an issue now in case anyone has any ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:24

github_iconTop GitHub Comments

3reactions
SalahAdDincommented, Apr 9, 2017

Now we have django 1.11 and this bug isn’t solved yet.

3reactions
zlorfcommented, Oct 24, 2016

I need a moment of free time to take a deep look into the issue; probably will take care of it at the incoming weekend.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django 1.10 default manager not MultilingualManager for model ...
Django 1.10 default manager not MultilingualManager for model inheriting abstract class with a manager defined on objects (leading to AttributeError: 'QuerySet' ...
Read more >
python - Django manager queries don't work in a chain of ...
Django manager queries don't work in a chain of queries. AttributeError: 'QuerySet' object has no attribute <the manager method> ; ViewStatistic.
Read more >
Django Model Object Has No Attribute 'Defaultmanager ...
Django 1.10 default manager not MultilingualManager for model inheriting abstract class AttributeError: 'QuerySet' object has no attribute 'rewrite'.
Read more >
Custom Model Manager queries in abstract classes-django
objects = BookManager() class Meta: abstract = True class Page(models. ... Exception Type: AttributeError Exception Value: 'Options' object has no attribute ...
Read more >
Django Queryset not working after tranformation to Abstract ...
For more than a year, I construct many of my query using a Django Model where I have simple relation between none abstract...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found