Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.1] - 2025-11-30

### Fixed

- Fixed compatibility with `fastapi>=0.121.3`
- FastAPI `Depends` [was changed to a frozen dataclass in `v0.121.3`](https://fastapi.tiangolo.com/release-notes/#01213).
- Engin no longer attaches a magic `__engin__` attribute to `Depends` for dependency detection in the `engin graph` tool.
- FastAPI dependencies created via `engin.Inject()` are now identified by a dedicated function name (`__inner_engin_dependency__`).

## [0.3.0] - 2025-11-12

### Added
Expand Down
13 changes: 8 additions & 5 deletions src/engin/extensions/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ def graph(self) -> list[Node]:


def Inject(interface: type[T]) -> Depends:
async def inner(conn: HTTPConnection) -> T:
async def __inner_engin_dependency__(conn: HTTPConnection) -> T:
try:
assembler: Assembler = conn.app.state.assembler
except AttributeError:
raise RuntimeError("Assembler is not attached to Application state") from None
return await assembler.build(interface)

dep = Depends(inner)
dep.__engin__ = True # type: ignore[attr-defined]
return dep
return Depends(__inner_engin_dependency__)


class _FastAPIDependencyGrapher(DependencyGrapher):
Expand Down Expand Up @@ -181,7 +179,12 @@ def _is_injected_param(param: Parameter) -> bool:
args = typing.get_args(param.annotation)
if len(args) != 2:
return False
return isinstance(args[1], Depends) and hasattr(args[1], "__engin__")
return (
isinstance(args[1], Depends)
and (depenency_function := getattr(args[1], "dependency", None)) is not None
and inspect.isfunction(depenency_function)
and depenency_function.__name__ == "__inner_engin_dependency__"
)

@property
def name(self) -> str:
Expand Down