Skip to content

Keep ResultDict unchanged when ResultDict.measurements raises an exception - #8423

Open
pavoljuhas wants to merge 1 commit into
quantumlib:mainfrom
pavoljuhas:no-mutation-on-valueerror
Open

pavoljuhas wants to merge 1 commit into
quantumlib:mainfrom
pavoljuhas:no-mutation-on-valueerror

Conversation

@pavoljuhas

Copy link
Copy Markdown
Collaborator

Problem: After ResultDict.measurements raises ValueError,
a second call would pass instead of raising ValueError again.

Solution: Avoid mutating ResultDict until the measurements
map is successfully resolved.

…lved

Problem: After `ResultDict.measurements` raises ValueError,
a second call would pass instead of raising ValueError again.

Solution: Avoid mutating `ResultDict` until the measurements
map is successfully resolved.
@pavoljuhas
pavoljuhas requested a review from a team as a code owner October 10, 2026 01:49
@github-actions github-actions Bot added the size: S 10< lines changed <50 label Oct 10, 2026
@pavoljuhas pavoljuhas changed the title Keep ResultDict unchanged when ResultDict.measurements cannot be resolved Keep ResultDict unchanged when ResultDict.measurements raises an exception Oct 10, 2026
@pavoljuhas

Copy link
Copy Markdown
Collaborator Author

NB: Plugging a corner case found whilst reviewing #8352.

@pavoljuhas pavoljuhas added the ci/no-release Use this label for pull request that should not have Cirq pre-release on PyPI. label Oct 10, 2026
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.59%. Comparing base (1403830) to head (125bb7e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8423   +/-   ##
=======================================
  Coverage   99.59%   99.59%           
=======================================
  Files        1133     1133           
  Lines      103919   103921    +2     
=======================================
+ Hits       103498   103500    +2     
  Misses        421      421           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mhucka mhucka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Noticed a possible deficiency in the test.

Comment on lines +90 to 91
with pytest.raises(ValueError, match="Cannot extract 2D measurements"):
_ = r.measurements

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since the PR description says

After ResultDict.measurements raises ValueError, a second call would pass instead of raising ValueError again

should this test be repeated here? I.e.,

Suggested change
with pytest.raises(ValueError, match="Cannot extract 2D measurements"):
_ = r.measurements
with pytest.raises(ValueError, match="Cannot extract 2D measurements"):
_ = r.measurements
# Check that a second access raises ValueError again.
with pytest.raises(ValueError, match="Cannot extract 2D measurements"):
_ = r.measurements

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

Labels

ci/no-release Use this label for pull request that should not have Cirq pre-release on PyPI. size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants