Skip to content

Commit 3370053

Browse files
committed
@bisgaard-itis review: doc
1 parent f7f3b24 commit 3370053

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/service-library/src/servicelib/fastapi/lifespan_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ class LifespanExpectedCalledError(LifespanError):
3232

3333

3434
def is_lifespan_called(state: State, lifespan_name: str) -> bool:
35+
# NOTE: This assert is meant to catch a common mistake:
36+
# The `lifespan` function should accept up to two *optional* positional arguments: (app: FastAPI, state: State).
37+
# Valid signatures include: `()`, `(app)`, `(app, state)`, or even `(_, state)`.
38+
# It's easy to accidentally swap or misplace these arguments.
3539
assert not isinstance( # nosec
3640
state, FastAPI
37-
), "TIP: lifespan func has (app, state) positional arguments"
41+
), "Did you swap arguments? `lifespan(app, state)` expects (app: FastAPI, state: State)"
3842

3943
called_lifespans = state.get(_CALLED_LIFESPANS_KEY, set())
4044
return lifespan_name in called_lifespans

0 commit comments

Comments
 (0)