Skip to content

fix(caching): avoid storing metadata and results for CachingBehavior.IGNORE nodes - #1716

Open
Shoryamishra61 wants to merge 2 commits into
apache:mainfrom
Shoryamishra61:fix-ignore-cache-metadata-1704
Open

Shoryamishra61 wants to merge 2 commits into
apache:mainfrom
Shoryamishra61:fix-ignore-cache-metadata-1704

Conversation

@Shoryamishra61

Copy link
Copy Markdown

Fixes #1704

Description

CachingBehavior.IGNORE is documented as "Results are never stored nor versioned" (adapter.py), but was previously included in the metadata storage branch in do_node_execute and the result storage branch in post_node_execute. Because pre_node_execute returns early for IGNORE nodes without creating a cache_key, storing metadata resulted in entries with cache_key = NULL. In SQLite, INSERT OR IGNORE does not treat NULL as duplicate, leading to orphaned metadata entries accumulating on every run for ignored nodes.

Changes

  • In hamilton/caching/adapter.py:
    • do_node_execute: removed CachingBehavior.IGNORE from the metadata persistence block, restricting it to CachingBehavior.RECOMPUTE.
    • post_node_execute: removed CachingBehavior.IGNORE from the result store persistence block, keeping only DEFAULT and RECOMPUTE.
    • Kept node execution of IGNORE nodes and the "<ignore>" dependency version marker used by downstream nodes intact.
  • In tests/caching/test_integration.py:
    • Updated test_ignore_behavior assertions to confirm that repeated executions with an ignored node do not increase metadata store size beyond the new <ignore> key created for downstream nodes.
    • Added test_ignore_behavior_from_start verifying that when a node is ignored from run 1, it writes 0 metadata entries and 0 result store entries, while downstream nodes can still cache under the <ignore> dependency key.

How I tested this

  • Ran focused regression tests:
    pytest tests/caching/test_integration.py -k "test_ignore_behavior" -vv
  • Ran full caching integration test suite:
    pytest tests/caching/test_integration.py -vv
  • Ran full caching test suite:
    pytest tests/caching/ -vv
  • Ran pre-commit hooks (ruff check, ruff format, license headers, etc.):
    pre-commit run --files hamilton/caching/adapter.py tests/caching/test_integration.py

Checklist

  • PR has an informative and human-readable title (this will be pulled into the release notes)
  • Changes are limited to a single goal (no scope creep)
  • Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future TODOs are captured in comments
  • Project documentation has been updated if adding/changing functionality.

Copilot AI lite review requested due to automatic review settings September 19, 2026 20:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The moderate test assertion issue remains unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes CachingBehavior.IGNORE so ignored nodes do not persist cache metadata or results while downstream caching remains supported.

Changes:

  • Restricts metadata persistence to RECOMPUTE.
  • Restricts result persistence to DEFAULT and RECOMPUTE.
  • Updates integration coverage for ignored nodes and downstream <ignore> keys.

Review finding: Moderate — Strengthen the assertion at tests/caching/test_integration.py:522 to verify the fresh result store contains exactly B’s single entry.

File Summary
tests/​caching/​test_integration.py Updates ignore-behavior expectations and adds regression coverage.
hamilton/​caching/​adapter.py Prevents metadata and result persistence for ignored nodes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/caching/test_integration.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved review comments, and regression coverage is included.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified, and regression coverage is included.

Review effort: Lite
Findings: None

This branch has not been deployed

No deployments
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.

CachingBehavior.IGNORE stores metadata rows on every run, contradicting its own docstring

2 participants