Skip to content

functools.cache on property accessors leaks instances and returns wrong values across same-id objects - #233

Draft
NandaScott wants to merge 1 commit into
developfrom
sandcastle/issue-230
Draft

functools.cache on property accessors leaks instances and returns wrong values across same-id objects#233
NandaScott wants to merge 1 commit into
developfrom
sandcastle/issue-230

Conversation

@NandaScott

Copy link
Copy Markdown
Owner

Closes #230

Opened by Sandcastle. 1 commit(s) on sandcastle/issue-230.

…230)

functools.cache keyed on self via __hash__/__eq__, causing two problems:
instances were never GC'd (cache held strong refs), and objects sharing a
Scryfall ID silently returned each other's cached values.  Switching all
three accessors (ScryfallListMixin.data, GameplayFieldsMixin.all_parts,
GameplayFieldsMixin.card_faces) to cached_property stores the value in the
instance __dict__, so it dies with the instance and cannot bleed across
objects.  Also corrects the __hash__ docstring (said "class name" but the
fallback is hash(id(self))).  Regression tests added for GC and isolation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@NandaScott
NandaScott marked this pull request as draft August 11, 2026 17:55
@NandaScott

Copy link
Copy Markdown
Owner Author

Wasn't expecting sandcastle to open this PR. Drafted until I can verify the claims in the original issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

functools.cache on property accessors leaks instances and returns wrong values across same-id objects

1 participant