﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23726	Unhelpful Python 3 error message when loading app with misconfigured manager	Peter Inglesby	Peter Inglesby	"I had a model whose `objects` class attribute was a subclass of `models.Manager`, and not an instance of a subclass of `models.Manager`.  That is, I had the following:

{{{
class Track(models.Model):
    ...
    objects = TrackManager
    ...
}}}

With Python 2.7, when `django.setup()` gets called, I get a helpful error message:

{{{
$ python2.7 manage.py shell
Traceback (most recent call last):
  File ""manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/Users/peteringlesby/.virtualenvs/django_katas/lib/python2.7/site-packages/django/core/management/__init__.py"", line 385, in execute_from_command_line
    utility.execute()
  File ""/Users/peteringlesby/.virtualenvs/django_katas/lib/python2.7/site-packages/django/core/management/__init__.py"", line 354, in execute
    django.setup()
  File ""/Users/peteringlesby/.virtualenvs/django_katas/lib/python2.7/site-packages/django/__init__.py"", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File ""/Users/peteringlesby/.virtualenvs/django_katas/lib/python2.7/site-packages/django/apps/registry.py"", line 108, in populate
    app_config.import_models(all_models)
  File ""/Users/peteringlesby/.virtualenvs/django_katas/lib/python2.7/site-packages/django/apps/config.py"", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File ""/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py"", line 37, in import_module
    __import__(name)
  File ""/Users/peteringlesby/projects/django_katas/katas/models.py"", line 26, in <module>
    class Track(models.Model):
  File ""/Users/peteringlesby/.virtualenvs/django_katas/lib/python2.7/site-packages/django/db/models/base.py"", line 170, in __new__
    new_class.add_to_class(obj_name, obj)
  File ""/Users/peteringlesby/.virtualenvs/django_katas/lib/python2.7/site-packages/django/db/models/base.py"", line 299, in add_to_class
    value.contribute_to_class(cls, name)
TypeError: Error when calling the metaclass bases
    unbound method contribute_to_class() must be called with TrackManager instance as first argument (got ModelBase instance instead)
}}}

With Python 3.4, I don't:

{{{
$ python3.4 manage.py shell
Traceback (most recent call last):
  File ""manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py"", line 385, in execute_from_command_line
    utility.execute()
  File ""/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py"", line 354, in execute
    django.setup()
  File ""/usr/local/lib/python3.4/site-packages/django/__init__.py"", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File ""/usr/local/lib/python3.4/site-packages/django/apps/registry.py"", line 108, in populate
    app_config.import_models(all_models)
  File ""/usr/local/lib/python3.4/site-packages/django/apps/config.py"", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File ""/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/importlib/__init__.py"", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File ""<frozen importlib._bootstrap>"", line 2254, in _gcd_import
  File ""<frozen importlib._bootstrap>"", line 2237, in _find_and_load
  File ""<frozen importlib._bootstrap>"", line 2226, in _find_and_load_unlocked
  File ""<frozen importlib._bootstrap>"", line 1200, in _load_unlocked
  File ""<frozen importlib._bootstrap>"", line 1129, in _exec
  File ""<frozen importlib._bootstrap>"", line 1471, in exec_module
  File ""<frozen importlib._bootstrap>"", line 321, in _call_with_frames_removed
  File ""/Users/peteringlesby/projects/django_katas/katas/models.py"", line 26, in <module>
    class Track(models.Model):
  File ""/usr/local/lib/python3.4/site-packages/django/db/models/base.py"", line 170, in __new__
    new_class.add_to_class(obj_name, obj)
  File ""/usr/local/lib/python3.4/site-packages/django/db/models/base.py"", line 299, in add_to_class
    value.contribute_to_class(cls, name)
TypeError: contribute_to_class() missing 1 required positional argument: 'name'
}}}"	Bug	closed	Uncategorized	1.7	Normal	invalid			Unreviewed	0	0	0	0	0	0
