Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.8 compatibility #404

Closed
hwkns opened this issue Mar 26, 2015 · 9 comments
Closed

Django 1.8 compatibility #404

hwkns opened this issue Mar 26, 2015 · 9 comments
Milestone

Comments

@hwkns
Copy link
Contributor

hwkns commented Mar 26, 2015

I'm currently seeing this stack trace, from an error related to django-wiki's use of mptt, when running any management command, in Django 1.8c1:

Traceback (most recent call last):
  File "/var/www/streisand/streisand/manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 312, in execute
    django.setup()
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/vagrant/.venv/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2203, 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 1448, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/vagrant/.venv/src/wiki/wiki/models/__init__.py", line 14, in <module>
    from .urlpath import *
  File "/home/vagrant/.venv/src/wiki/wiki/models/urlpath.py", line 40, in <module>
    class URLPath(MPTTModel):
  File "/home/vagrant/.venv/lib/python3.4/site-packages/mptt/models.py", line 244, in __new__
    cls = meta.register(cls)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/mptt/models.py", line 319, in register
    manager.init_from_model(cls)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/mptt/managers.py", line 51, in init_from_model
    [tree_field] = [fld for fld in model._meta.get_fields_with_model() if fld[0].name == self.tree_id_attr]
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/db/models/options.py", line 56, in wrapper
    return fn(*args, **kwargs)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/db/models/options.py", line 432, in get_fields_with_model
    return [self._map_model(f) for f in self.get_fields()]
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/db/models/options.py", line 740, in get_fields
    return self._get_fields(include_parents=include_parents, include_hidden=include_hidden)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/db/models/options.py", line 802, in _get_fields
    all_fields = self._relation_tree
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/utils/functional.py", line 60, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/db/models/options.py", line 709, in _relation_tree
    return self._populate_directed_relation_graph()
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/db/models/options.py", line 681, in _populate_directed_relation_graph
    all_models = self.apps.get_models(include_auto_created=True)
  File "/home/vagrant/.venv/lib/python3.4/functools.py", line 428, in wrapper
    result = user_function(*args, **kwds)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/apps/registry.py", line 168, in get_models
    self.check_models_ready()
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/apps/registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

This error is similar to an error in django-tagging that was recently fixed with a hack in django-mptt. Even with the hack working, I thought you might want to be notified of the issue; django-wiki should not be using models during setup.

After I installed django-mptt master (which is now django-mptt 0.7.1) to fix that issue, I ran into this error when submitting content for the root article:

Traceback (most recent call last):
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
    response = self.get_response(request)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/core/handlers/base.py", line 218, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/core/handlers/base.py", line 261, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django_extensions/management/technical_response.py", line 5, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/six.py", line 659, in reraise
    raise value
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "/home/vagrant/.venv/src/wiki/wiki/decorators.py", line 182, in wrapper
    return func(request, article, *args, **kwargs)
  File "/home/vagrant/.venv/lib/python3.4/site-packages/django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/home/vagrant/.venv/src/wiki/wiki/views/article.py", line 47, in dispatch
    **kwargs)
  File "/home/vagrant/.venv/src/wiki/wiki/views/mixins.py", line 30, in dispatch
    str(e))
Exception: Attribute error most likely caused by wrong MPTT version. Use 0.5.3+.

'TreeQuerySet' object has no attribute 'can_read'

The other problem I'm seeing is just an annoyance (for now):

System check identified some issues:

WARNINGS:
wiki.ArticleRevision.ip_address: (fields.W900) IPAddressField has been deprecated. Support for it (except in historical migrations) will be removed in Django 1.9.
    HINT: Use GenericIPAddressField instead.
wiki.RevisionPluginRevision.ip_address: (fields.W900) IPAddressField has been deprecated. Support for it (except in historical migrations) will be removed in Django 1.9.
    HINT: Use GenericIPAddressField instead.
@hwkns
Copy link
Contributor Author

hwkns commented Apr 6, 2015

Problems persist in the final release of Django 1.8.

@yuriiz
Copy link

yuriiz commented Apr 7, 2015

Adding django-mptt>=0.7.1 should fix the problem.

@hwkns
Copy link
Contributor Author

hwkns commented Apr 7, 2015

@yuriiz please read what I wrote. The error happens on the latest release version of django-mptt (0.7.1) and also on the master branch.

@benjaoming
Copy link
Member

This is actually not a problem with Django 1.8, I can recreate it with 1.7, too.

@benjaoming benjaoming added this to the 0.1 milestone Apr 22, 2015
@benjaoming
Copy link
Member

Problem persists in mptt 0.7.2 despite django-mptt/django-mptt@6b5ac07

@benjaoming
Copy link
Member

Error seems to be that django-mptt's model instance function get_children() returns a TreeQuerySet where it should be returning the queryset type defined in the custom manager's get_queryset method.

@benjaoming
Copy link
Member

I think the error comes from this line in django-mptt, not sure who's to blame... after Django removed EmptyQuerySet, it has been quite odd where one's supposed to implement one's own custom version of empty querysets...

mptt.models

class MPTTModel(six.with_metaclass(MPTTModelBase, models.Model)):
    """
    Base class for tree models.
    """
    ...

    @raise_if_unsaved
    def get_children(self):
        ...
            if self.is_leaf_node():
                return self._tree_manager.none()  # <- THIS LINE

@benjaoming
Copy link
Member

Should be fixed in 561f856

@benjaoming
Copy link
Member

The line uncommented can actually be re-enabled if it had any cause once this PR in django-mptt is released:

django-mptt/django-mptt#372

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants