Skip to content

Commit 08796fa

Browse files
committed
Deepcopy the cache
1 parent 4e69cb7 commit 08796fa

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

sentry_sdk/_lru_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
6363
"""
6464

65-
from copy import copy, deepcopy
65+
from copy import deepcopy
6666

6767
SENTINEL = object()
6868

@@ -94,7 +94,7 @@ def __init__(self, max_size):
9494
def __copy__(self):
9595
cache = LRUCache(self.max_size)
9696
cache.full = self.full
97-
cache.cache = copy(self.cache)
97+
cache.cache = deepcopy(self.cache)
9898
cache.root = deepcopy(self.root)
9999
return cache
100100

tests/test_lru_cache.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ def test_cache_copy():
7676
cache.get(1)
7777
assert copied.get_all() == [(1, 1), (2, 2), (3, 3)]
7878
assert cache.get_all() == [(2, 2), (3, 3), (1, 1)]
79+
80+
81+
def test_cache_no_overwrites_to_parent():
82+
cache1 = LRUCache(max_size=2)
83+
cache1.set(1, True)
84+
cache2 = cache1.__copy__()
85+
cache2.set(1, False)
86+
assert cache1.get(1) is True
87+
assert cache2.get(1) is False

0 commit comments

Comments
 (0)