Skip to content

Django 1.10 functional middleware compatibility #878

Closed
@ryankask

Description

@ryankask

debug_toolbar.apps.is_middlware_class() is used in a check for middleware ordering issues.

It assumes that all middleware in MIDDLEWARE are classes and doesn't account for Django 1.10's functional middleware.

If a functional middleware factory is present, it fails when it hits issubclass() since the first argument isn't a class.

I will try to submit a patch this weekend because I need to clone the project and get the test suite running but a simple solution would be tweak it:

def is_middleware_class(middleware_class, middleware_path):
    try:
        middleware_cls = import_string(middleware_path)
    except ImportError:
        return
    try:
        return issubclass(middleware_cls, middleware_class)
    except TypeError:
        return False

Perhaps there is a more elegant check using the types module but I would need to read about Py2/3 compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions