Skip to content

Keyword only args causes RequestMiddleware to fail on Django app load #112

@bradykieffer

Description

@bradykieffer

Environment details

  • OS type and version: macOS version 11.0.1
  • Python version: Python 3.8.2
  • pip version: pip 20.2.4
  • google-cloud-logging version: 2.0.1 and 2.0.0

Steps to reproduce

  1. Add google.cloud.logging_v2.handlers.middleware.RequestMiddleware to a MIDDLEWARE list in django app settings
  2. Make an API request, e.g. during a test

Stack trace

self = <django.test.client.ClientHandler object at 0x124a5f850>

    def load_middleware(self):
        """
        Populate middleware lists from settings.MIDDLEWARE.

        Must be called after the environment is fixed (see __call__ in subclasses).
        """
        self._view_middleware = []
        self._template_response_middleware = []
        self._exception_middleware = []

        handler = convert_exception_to_response(self._get_response)
        for middleware_path in reversed(settings.MIDDLEWARE):
            middleware = import_string(middleware_path)
            try:
>               mw_instance = middleware(handler)
E               TypeError: __init__() takes 1 positional argument but 2 were given

Extra Info

It looks like django doesn't support keyword only arguments when loading middleware (the link is pointing to master, but it's the same for old versions). If I locally do the following, I can subclass the RequestMiddleware and remove the keyword only args and the whole issue goes away

Metadata

Metadata

Assignees

Labels

api: loggingIssues related to the googleapis/python-logging API.triage meI really want to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions