Skip to content

fix: a refused detach no longer starts the drop grace - #112

Merged
AlexeyShalaev merged 1 commit into
masterfrom
fix/105-refused-detach-unstamped
Oct 16, 2026
Merged

AlexeyShalaev merged 1 commit into
masterfrom
fix/105-refused-detach-unstamped

Conversation

@AlexeyShalaev

Copy link
Copy Markdown
Member

Closes #105.

Two changes, each enough on its own for the case in the issue. Together they also keep an attached partition from carrying a comment that says it was detached.

  • _mark_orphaned keeps an existing detached-at only while the table is detached or has a detach pending (pg_inherits.inhdetachpending). On a partition that is still plainly attached, the instant is a leftover, so the detach records its own (orphan_comment(..., keep_instant=False)). The unpinned concurrent path no longer skips tables that already carry a marker; it goes through the same rule.
  • _unmark_if_refused: after a 55006 or 23503 refusal on either concurrent path, the marker lines come off and the comment the table had before stays. This runs under SHARE UPDATE EXCLUSIVE on the partition, which is what COMMENT takes anyway, checked against the expected OID, and only while the partition is still plainly attached. It is best effort: if it fails, a warning is logged, the refusal is still what the run reports, and the stamp rule keeps a leftover harmless. 42P01 is left alone, since there is no table to fix.

The test (both mirrors) uses a June partition held by a foreign key, with a comment of its own, and DropAfter(grace=30 days):

  1. A run on 2026-08-26 is refused; afterwards June's comment is still exactly june archive.
  2. The reference is deleted, and a run on 2026-08-28 detaches June.
  3. Its stamp is 2026-08-28 and the comment ends with june archive.

Without the change the first assertion fails: the comment still carries the marker.

Results: unit 2872 passed, integration (PG 17) 579 passed, ruff and mypy clean. sync_tests_mirror.py also rewrote three unrelated files (the known drift); I reverted those and kept only test_foreign_keys.py.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 16 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pg_partsmith/aio/repositories/remover.py 62.06% 9 Missing and 2 partials ⚠️
pg_partsmith/sync/repositories/remover.py 83.33% 3 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

A refused DETACH ... CONCURRENTLY left its orphan marker, detached-at included, on a partition that stayed attached, and later detaches kept that instant, so DropAfter's grace counted from the first refusal. A refusal (55006, 23503) now takes the marker back off, keeping the table's own comment, and a detach of a still-attached partition always records its own instant.

Closes #105
@AlexeyShalaev
AlexeyShalaev force-pushed the fix/105-refused-detach-unstamped branch from 6f1ea65 to d505fbb Compare October 16, 2026 18:50
@AlexeyShalaev
AlexeyShalaev merged commit fdbfb81 into master Oct 16, 2026
31 of 32 checks passed
@AlexeyShalaev
AlexeyShalaev deleted the fix/105-refused-detach-unstamped branch October 16, 2026 19:54
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.

A refused DETACH CONCURRENTLY leaves its detached-at stamp, so DropAfter grace counts from the failed attempt

1 participant