fix: add deepcopy on the way into MemoryCache#444
Merged
danielolsen merged 2 commits intodevelopfrom Apr 7, 2021
Merged
Conversation
jenhagg
approved these changes
Apr 6, 2021
BainanXia
reviewed
Apr 6, 2021
Comment on lines
+71
to
+78
| def test_mem_cache_put_version_never_changes(): | ||
| cache = MemoryCache() | ||
| key = cache_key("foo", 4) | ||
| obj = {"key1": 42} | ||
| cache.put(key, obj) | ||
| obj["key2"] = 8675309 | ||
| assert "key2" not in cache.get(key) |
Collaborator
There was a problem hiding this comment.
Can we simplify this test to make it easier to read such as:
def test_mem_cache_put_version_never_changes():
cache = MemoryCache()
obj = {"key1": "val1"}
cache.put("foo", obj)
obj["key2"] = "val2"
assert "key2" not in cache.get("foo")
Contributor
Author
There was a problem hiding this comment.
Sure. I was basically copying and pasting from the test above, but I agree that yours is clearer about what we're trying to do. We could also assert "key1" in cache.get(key).
Collaborator
There was a problem hiding this comment.
Maybe also assert obj is not cache.get(key)? And possibly assert obj == cache.get(key)
Contributor
Author
There was a problem hiding this comment.
I think test_mem_cache_get_returns_copy already catches the first one.
05ad0fb to
d7af92b
Compare
BainanXia
approved these changes
Apr 7, 2021
danielolsen
added a commit
that referenced
this pull request
Apr 7, 2021
danielolsen
added a commit
that referenced
this pull request
Apr 7, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Addresses #443.
What is the code doing
Add a deepcopy on the way into the cache, so any modifications to the first returned object don't affect the object in the cache.
Testing
Time estimate
30 seconds to understand, more time possibly to discuss.