Skip to content

Commit 8cc2c11

Browse files
committed
Fix issue #398 with FastAPI request importing
1 parent 6c06548 commit 8cc2c11

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

docs/main/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ that were made in every particular version.
77
From version 0.7.6 *Dependency Injector* framework strictly
88
follows `Semantic versioning`_
99

10+
Development version
11+
-------------------
12+
- Hotfix a bug with importing FastAPI ``Request``.
13+
See issue: `#398 <https://github.com/ets-labs/python-dependency-injector/issues/398>`_.
14+
Thanks to `@tapm <https://github.com/tapm>`_ for reporting the bug.
15+
1016
4.23.0
1117
------
1218
- Add support of aliases for ``Configuration`` provider.

src/dependency_injector/wiring.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,13 @@ def _unpatch(
345345
def _fetch_reference_injections(
346346
fn: Callable[..., Any],
347347
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
348-
# # Hotfix, see: https://github.com/ets-labs/python-dependency-injector/issues/362
349-
if GenericAlias and fn is GenericAlias:
348+
# Hotfix, see:
349+
# - https://github.com/ets-labs/python-dependency-injector/issues/362
350+
# - https://github.com/ets-labs/python-dependency-injector/issues/398
351+
if GenericAlias and any((
352+
fn is GenericAlias,
353+
getattr(fn, '__func__', None) is GenericAlias
354+
)):
350355
fn = fn.__init__
351356

352357
signature = inspect.signature(fn)

tests/unit/samples/wiringfastapi/web.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22

33
from fastapi import FastAPI, Depends
4+
from fastapi import Request # See: https://github.com/ets-labs/python-dependency-injector/issues/398
45
from fastapi.security import HTTPBasic, HTTPBasicCredentials
56
from dependency_injector import containers, providers
67
from dependency_injector.wiring import inject, Provide

0 commit comments

Comments
 (0)