Skip to content

Incompatibility with quart-cors #65

Description

@vagran

Description

It seems to be incompatible with quart-cors.

app=Quart(__name__)
app=cors(app, allow_origin="*")
@app.get("/projectInfo")asyncdefGetProjectInfo(curProject: injector.Inject[CurProject]):
...
...
quart_injector.wire(app, configure)
app.run(host=config.server.address, port=config.server.port, debug=True)

produces this error:

[ERROR] Error in ASGI Framework
Traceback (most recent call last):
File ".venv/lib/python3.13/site-packages/hypercorn/asyncio/task_group.py", line 28, in _handle
await app(scope, receive, send, sync_spawn, call_soon)
File ".venv/lib/python3.13/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
await self.app(scope, receive, send)
File ".venv/lib/python3.13/site-packages/quart/app.py", line 1735, in __call__
await self.asgi_app(scope, receive, send)
File ".venv/lib/python3.13/site-packages/quart/app.py", line 1761, in asgi_app
await asgi_handler(receive, send)
File ".venv/lib/python3.13/site-packages/quart/asgi.py", line 60, in __call__
raise_task_exceptions(done)
~~~~~~~~~~~~~~~~~~~~~^^^^^^
File ".venv/lib/python3.13/site-packages/quart/utils.py", line 186, in raise_task_exceptions
raise task.exception()
File ".venv/lib/python3.13/site-packages/quart/asgi.py", line 110, in handle_request
response = await _handle_exception(self.app, error)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/quart/asgi.py", line 408, in _handle_exception
raise error
File ".venv/lib/python3.13/site-packages/quart/asgi.py", line 108, in handle_request
response = await self.app.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/quart/app.py", line 1468, in handle_request
return await self.handle_exception(error)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/quart/app.py", line 1464, in handle_request
return await self.full_dispatch_request(request_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/quart/app.py", line 1503, in full_dispatch_request
return await self.finalize_request(result, request_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/quart/app.py", line 1630, in finalize_request
response = await self.process_response(response, request_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/quart/app.py", line 1691, in process_response
response = await self.ensure_async(function)(response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/quart_injector/wiring.py", line 85, in view
return await container.call_with_injection(async_func, None, args, kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.13/site-packages/injector/__init__.py", line 1122, in call_with_injection
bindings = get_bindings(callable)
File ".venv/lib/python3.13/site-packages/injector/__init__.py", line 1259, in get_bindings
type_hints = get_type_hints(callable, include_extras=True)
File "/usr/lib/python3.13/typing.py", line 2496, in get_type_hints
raise TypeError('{!r} is not a module, class, method, '
'or function.'.format(obj))
TypeError: functools.partial(<function _after_request at 0x7fb05bfffce0>, allow_credentials=None, allow_headers=None, allow_methods=None, allow_origin='*', expose_headers=None, max_age=None, send_origin_wildcard=None) is not a module, class, method, or function.

I have this monkey-patching workaround (not sure if it handles all scenarios):

_original_get_bindings=injector.get_bindingsdefget_bindings_safe(callable):
ifisinstance(callable, functools.partial):
return {}
return_original_get_bindings(callable)
injector.get_bindings=get_bindings_safe

Motivation

Prevents from using the library

Expected behavior

Should work normally

Actual behavior

Exception

Steps to reproduce

In the description

Version

0.0.0b1

Environment

Python 3.13.11

Link to code

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions