Skip to content

Commit

Permalink
fix(scope): Revert scope state regression (#3075)
Browse files Browse the repository at this point in the history
Revert scope state regression
  • Loading branch information
provinzkraut authored Feb 6, 2024
1 parent 04dd5b5 commit 9fad4b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions litestar/utils/scope/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ def from_scope(cls, scope: Scope) -> Self:
Returns:
A `ConnectionState` object.
"""
base = scope["state"] if "state" in scope else scope
if (state := base.get(CONNECTION_STATE_KEY)) is None:
state = base[CONNECTION_STATE_KEY] = cls()
base_scope_state = scope.setdefault("state", {})
if (state := base_scope_state.get(CONNECTION_STATE_KEY)) is None:
state = base_scope_state[CONNECTION_STATE_KEY] = cls()
return state


Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_utils/test_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def scope(create_scope: Callable[..., Scope]) -> Scope:
def test_from_scope_without_state() -> None:
scope = {} # type: ignore[var-annotated]
state = ScopeState.from_scope(scope) # type: ignore[arg-type]
assert "state" not in scope
assert scope[CONNECTION_STATE_KEY] is state
assert scope["state"][CONNECTION_STATE_KEY] is state


@pytest.mark.parametrize(("pop",), [(True,), (False,)])
Expand Down

0 comments on commit 9fad4b5

Please sign in to comment.