Skip to content

test(versioning): stub the locking re-read so run() reaches the patched restore seams - #44437

Open
kokhlo wants to merge 1 commit into
apache:masterfrom
kokhlo:kokhlo/fix-restore-version-tests
Open

kokhlo wants to merge 1 commit into
apache:masterfrom
kokhlo:kokhlo/fix-restore-version-tests

Conversation

@kokhlo

@kokhlo kokhlo commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the six master-red tests in tests/unit_tests/commands/test_base_restore_version_command.py (#44436) so unit-tests-required stops reddening every PR built against master's tip.

The two failing drivers feed run() a bare MagicMock() entity. Since #44015, _do_restore() issues a real locking re-read (populate_existing().with_for_update()) before resolve_version, and the mock's auto-created id cannot bind into that query (sqlite3.ProgrammingError). The @transaction(catches=(SQLAlchemyError, LookupError)) wrapper translates the binding error into failed_exc, so the patched resolve_version / restore_version seams are never reached — producing exactly the six reported failures (wrong __cause__, and the "passes through untranslated" driver seeing a translated error).

Fix is test-side, per the issue: _validate_context now gives the mock entity a real integer id and stubs superset.commands.version_restore.db with a self-returning query chain whose one_or_none() hands the entity back — the same wiring test_restore_version_concurrency.py already uses for the lock itself. validate()-only tests are unaffected; the row lock in _do_restore() is untouched.

Test plan

  • RED on pristine master: exactly the six tests from the issue fail (6 failed, 6 passed)
  • GREEN with the patch: 12 passed for the full file
  • Neighbours unaffected: test_restore_version_concurrency.py + tests/unit_tests/versioning = 291 passed
  • ruff check + ruff format --check clean

Closes #44436

@bito-code-review

bito-code-review Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #ecf374

Actionable Suggestions - 0
Additional Suggestions - 1
  • tests/unit_tests/commands/test_base_restore_version_command.py - 1
    • Misleading docstring rationale · Line 57-62
      The docstring says a bare MagicMock id "cannot bind into the FOR UPDATE query (sqlite3.ProgrammingError)", implying `entity.id = 1` is required to avoid it. But the query chain is fully stubbed (`query.populate_existing/enable_eagerloads/filter_by/with_for_update/one_or_none` all return `query`/`entity`), so no bind ever reaches the DB. The real id is actually consumed by `build_action_headline(entity_kind, entity.id, ...)` in `_do_restore` (version_restore.py:189). The stated rationale is misleading for future maintainers.
Review Details
  • Files reviewed - 1 · Commit Range: 9bc5999..9bc5999
    • tests/unit_tests/commands/test_base_restore_version_command.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.64%. Comparing base (128c0c1) to head (9bc5999).

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #44437       +/-   ##
===========================================
+ Coverage   66.29%   80.64%   +14.35%     
===========================================
  Files        2942     2942               
  Lines      175692   175692               
  Branches    40788    40788               
===========================================
+ Hits       116467   141679    +25212     
+ Misses      56770    31353    -25417     
- Partials     2455     2660      +205     
Flag Coverage Δ
hive ?
mysql 56.38% <ø> (ø)
postgres 56.39% <ø> (-0.01%) ⬇️
presto 39.04% <ø> (ø)
python 84.93% <ø> (+28.22%) ⬆️
sqlite 56.10% <ø> (ø)
unit 76.77% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@kokhlo

kokhlo commented Sep 19, 2026

Copy link
Copy Markdown
Contributor Author

The only red check is test-postgres-hive, which failed in its Start hadoop and hive setup step before any test ran:

Error response from daemon: failed to set up container networking: driver failed
programming external connectivity on endpoint namenode (...):
failed to bind host port 0.0.0.0:50070/tcp: address already in use

Host-port collision on the shared runner, unrelated to this diff (test-only change; the same job is green on other PRs running today). Would a maintainer mind re-running that job, or I can push an empty commit if that's the preferred trigger — happy either way.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Six restore-version command unit tests fail on master, reddening unit-tests-required on every PR

1 participant