Skip to content

Commit

Permalink
fix: do not copy client
Browse files Browse the repository at this point in the history
If we copy the client, some bound models that where created during the cached session, will still hold  the reference to the cached_client, even outside the scope of the context manager.

By not copying the client, we ensure that the bound model client is not caching request outside the scope of the context.
  • Loading branch information
jooola committed Feb 1, 2024
1 parent 80f0756 commit 2dbf6e0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions hcloud/_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import copy
import time
from contextlib import contextmanager
from typing import Generator, NoReturn
Expand Down Expand Up @@ -251,9 +250,9 @@ def cached_session(self) -> Generator[Client, None, None]:
Cached response will not expire, therefore the cached client must not be used
for long living scopes.
"""
client = copy.deepcopy(self)
client.session(CachedSession())
yield client
self.session(CachedSession())
yield self
self.session(requests.Session())


class CachedSession(requests.Session):
Expand Down

0 comments on commit 2dbf6e0

Please sign in to comment.