Opened 10 years ago
Closed 10 years ago
#23726 closed Bug (invalid)
Unhelpful Python 3 error message when loading app with misconfigured manager
Reported by: | Peter Inglesby | Owned by: | Peter Inglesby |
---|---|---|---|
Component: | Uncategorized | Version: | 1.7 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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'
Change History (5)
comment:1 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Unbound methods don't exist on Python 3, they become simple functions.
I'm not sure we can do much to improve the situation.
comment:4 by , 10 years ago
Yeah... and since 1be03aff5c24e902b89503dda32891aa4881579e, no error is raised at all.
comment:5 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Looking at this again, Python 2 is only marginally less unhelpful than Python 3.