Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The cache could reuse a class inappropriately #1070

Merged
merged 1 commit into from
Feb 27, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Improvements
- Allow ICC correction to specify intent ([#1066](../../pull/1066))

### Bug Fixes
- The cache could reuse a class inappropriately ([#1070](../../pull/1070))

## 1.20.1

### Bug Fixes
Expand Down
7 changes: 3 additions & 4 deletions large_image/cache_util/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import functools
import threading

Expand Down Expand Up @@ -113,7 +112,6 @@ def __new__(metacls, name, bases, namespace, **kwargs): # noqa - N804
# Get metaclass parameters by finding and removing them from the class
# namespace (necessary for Python 2), or preferentially as metaclass
# arguments (only in Python 3).

cacheName = namespace.get('cacheName', None)
cacheName = kwargs.get('cacheName', cacheName)

Expand Down Expand Up @@ -192,12 +190,13 @@ def __call__(cls, *args, **kwargs): # noqa - N805
return result
except KeyError:
pass
# This conditionally copies a non-styled class and add a style.
# This conditionally copies a non-styled class and adds a style.
if kwargs.get('style') and hasattr(cls, '_setStyle'):
subkwargs = kwargs.copy()
subkwargs.pop('style')
subresult = cls(*args, **subkwargs)
result = copy.copy(subresult)
result = subresult.__class__.__new__(subresult.__class__)
result.__dict__ = subresult.__dict__.copy()
result._setStyle(kwargs['style'])
result._classkey = key
with cacheLock:
Expand Down
3 changes: 3 additions & 0 deletions test/test_cache_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def testCacheSourceStyle():
ts1 = large_image.open(imagePath)
ts2 = large_image.open(imagePath, style={'max': 128})
ts3 = large_image.open(imagePath, style={'max': 160})
assert id(ts1) != id(ts2)
assert id(ts2) != id(ts3)
tile1 = ts1.getTile(0, 0, 4)
assert ts1.getTile(0, 0, 4) is not None
assert ts2.getTile(0, 0, 4) is not None
Expand All @@ -33,6 +35,7 @@ def testCacheSourceStyleFirst():
imagePath = datastore.fetch('sample_image.ptif')
ts2 = large_image.open(imagePath, style={'max': 128})
ts1 = large_image.open(imagePath)
assert id(ts1) != id(ts2)
tile1 = ts1.getTile(0, 0, 4)
assert ts1.getTile(0, 0, 4) is not None
assert ts2.getTile(0, 0, 4) is not None
Expand Down