Skip to content

fix(xorq): use WeakKeyDictionary for _expr_count_cache to prevent id() reuse - #889

Merged
paddymul merged 1 commit into
mainfrom
fix/expr-count-cache-id-reuse
Jun 5, 2026
Merged

fix(xorq): use WeakKeyDictionary for _expr_count_cache to prevent id() reuse#889
paddymul merged 1 commit into
mainfrom
fix/expr-count-cache-id-reuse

Conversation

@paddymul

@paddymul paddymul commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • _expr_count_cache was a dict[int, int] keyed by id(expr) — the CPython memory address
  • When a GC'd expression's address was reused by a new expression, the cache returned a stale count
  • TestPostProcessing::test_filter_pushes_down caches count=4 for a filtered expr; after GC that address was reused by the 2-row search result in TestSearch::test_search_filters_via_quick_command_args, so filtered_rows read 4 instead of 2
  • This is the root cause of the CI failure on main (Python 3.12 run)

Fix

Switch _expr_count_cache to weakref.WeakKeyDictionary (keyed by the expression object itself). Entries are automatically evicted when the expression is GC'd, eliminating stale hits. Also update TestExprCountMemoization assertions that referenced id(stub) directly.

Test plan

  • pytest tests/unit/test_xorq_buckaroo_widget.py — all 43 pass locally
  • Full unit suite (1114 passed) — no regressions

🤖 Generated with Claude Code

…) 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>
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

📦 TestPyPI package published

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.dev27029977354

or 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.dev27029977354

MCP server for Claude Code

claude 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

@paddymul
paddymul added this pull request to the merge queue Jun 5, 2026
Merged via the queue into main with commit ec683bb Jun 5, 2026
27 checks passed
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.

1 participant