fix(xorq): use WeakKeyDictionary for _expr_count_cache to prevent id() reuse - #889
Merged
Conversation
…) reuse `_expr_count_cache` was keyed by `id(expr)`, which is the CPython memory address. When a GC'd expression's address was reused by a new expression, the cache returned a stale count for the new object. Concretely: `test_filter_pushes_down` cached count=4 for a filtered expr; after GC that address was reused by the 2-row search result in the next test, causing `filtered_rows` to read 4 instead of 2. Switching to `weakref.WeakKeyDictionary` (keyed by the expression object directly) means entries are evicted when the expression is GC'd, eliminating the false hit. Also update the `TestExprCountMemoization` assertions that referenced `id(stub)` directly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
📦 TestPyPI package publishedpip install --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo==0.14.12.dev27029977354or with uv: uv pip install --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo==0.14.12.dev27029977354MCP server for Claude Codeclaude mcp add buckaroo-table -- uvx --from "buckaroo[mcp]==0.14.12.dev27029977354" --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo-table📖 Docs preview🎨 Storybook preview |
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.
Summary
_expr_count_cachewas adict[int, int]keyed byid(expr)— the CPython memory addressTestPostProcessing::test_filter_pushes_downcaches count=4 for a filtered expr; after GC that address was reused by the 2-row search result inTestSearch::test_search_filters_via_quick_command_args, sofiltered_rowsread 4 instead of 2Fix
Switch
_expr_count_cachetoweakref.WeakKeyDictionary(keyed by the expression object itself). Entries are automatically evicted when the expression is GC'd, eliminating stale hits. Also updateTestExprCountMemoizationassertions that referencedid(stub)directly.Test plan
pytest tests/unit/test_xorq_buckaroo_widget.py— all 43 pass locally🤖 Generated with Claude Code