Skip to content

Fix flaky DeleteInvisibleLanesScript test#3043

Merged
jonathangreen merged 2 commits intomainfrom
chore/fix_delete_invisible_lanes_script_test
Feb 11, 2026
Merged

Fix flaky DeleteInvisibleLanesScript test#3043
jonathangreen merged 2 commits intomainfrom
chore/fix_delete_invisible_lanes_script_test

Conversation

@jonathangreen
Copy link
Member

@jonathangreen jonathangreen commented Feb 11, 2026

Description

Fix the flaky TestDeleteInvisibleLanesScript::test_do_run test by evaluating lane visibility before performing any deletions.

Motivation and Context

Lane.visible is a computed property that recursively checks parent visibility: self._visible and (not self.parent or self.parent.visible). When the original script interleaved _db.delete() calls with visible checks in the same loop, deleting a parent lane could trigger a SQLAlchemy autoflush when a child subsequently lazy-loaded its parent relationship. The autoflush would execute the pending DELETE and set parent_id = NULL on children, causing child.visible to return True, so the script would skip deleting the child.

This caused the test to be flaky, but could also cause the script to be flaky as well. The fix separates evaluation from mutation — all visibility checks happen before any _db.delete() calls, ensuring consistent parent references.

Example CI failure: https://github.com/ThePalaceProject/circulation/actions/runs/21918135183/job/63290798573

How Has This Been Tested?

Existing test TestDeleteInvisibleLanesScript::test_do_run covers this behavior and should now pass consistently.

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

…fore deleting

The Lane.visible property is computed recursively, checking parent visibility.
When the script interleaved _db.delete() calls with visibility checks in the
same loop, deleting a parent could trigger an autoflush during a child's
parent lazy-load, nullifying parent_id and making the child appear visible.
Separating evaluation from deletion ensures consistent visibility checks.
@jonathangreen jonathangreen force-pushed the chore/fix_delete_invisible_lanes_script_test branch from 828d11e to d578a39 Compare February 11, 2026 19:26
@jonathangreen jonathangreen added the bug Something isn't working label Feb 11, 2026
@jonathangreen jonathangreen requested a review from a team February 11, 2026 19:32
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.04%. Comparing base (194642f) to head (5b37768).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3043   +/-   ##
=======================================
  Coverage   93.04%   93.04%           
=======================================
  Files         480      480           
  Lines       43711    43712    +1     
  Branches     6029     6028    -1     
=======================================
+ Hits        40669    40670    +1     
  Misses       1972     1972           
  Partials     1070     1070           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

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

🛠️

@jonathangreen jonathangreen merged commit 0862033 into main Feb 11, 2026
19 checks passed
@jonathangreen jonathangreen deleted the chore/fix_delete_invisible_lanes_script_test branch February 11, 2026 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants