Skip to content

One event for every lifecycle hook, and the last silent disagreement from #27 - #31

Merged
AlexeyShalaev merged 6 commits into
masterfrom
fix/naive-bound-without-a-timezone
Sep 1, 2026
Merged

AlexeyShalaev merged 6 commits into
masterfrom
fix/naive-bound-without-a-timezone

Conversation

@AlexeyShalaev

@AlexeyShalaev AlexeyShalaev commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Closes the rest of #27. Four commits, smallest first.

1. The last silent disagreement (fix:)

Of the three settings that had to agree across the repository and the metadata provider, the marker prefix is now refused when it disagrees and the codec/timezone pair can be handed over as boundaries=config.time_boundaries. What remained was the case where nobody says anything: a timestamp or date key renders its bounds with no offset, so reading one back resolves it in some zone, and only the zone it was written under gives the same instant. With no ddl_timezone and no boundaries, the server's session default decides and is_partition_closed can answer hours early or late without a sound. It now warns, and only where there is a real question:

Bound Provider / call Warns
2026-02-01 00:00:00 nothing given yes
2026-02-01 00:00:00+00 nothing given no — the literal answers for itself
2026-02-01 00:00:00 ddl_timezone=… no
2026-02-01 00:00:00 boundaries=… no
an encoded id, MAXVALUE, an integer anything no — not a timestamp question

2. One event for every hook (feat:) — breaking

Three of the six phases were handed a PartitionInfo and three a bare string. A before_drop that archives a partition got a name and nothing else — and could not look the rest up either: DETACH clears relpartbound, so by drop time the database no longer records where the partition sat. The split was an accident of how the phases grew, and it showed twice more: the config was passed to create hooks only, and an audit or metrics hook could not be written except as six identical delegating methods.

Every hook method now takes one PartitionEvent:

Field What it is
phase which moment this is
config the table's configuration — not something a hook has to be given separately any more
partition PartitionInfo: name, bounds, OID, subpartition_type
window the period covered; None for a member of a root HASH or LIST, or when the name does not decode
operation the planned operation: reason, detail, oid, size_bytes, row_estimate, detached_at
table_name the root, derived from config so the two cannot drift

on_event is new: it fires for every phase in addition to the method named for it, so an audit trail is one method that a later phase extends rather than breaks.

Also breaking, in the same area: PlanExecutor.detach_single_partition / drop_single_partition and PartitionLifecycleService.detach_old_partitions / drop_detached_partitions take the config the event is built from, which is what every other entry point already took.

3. Two more phases (feat:)

A partition retention released is re-attached when its window is wanted again — retention grew, or create-ahead reached back to it — and that transition happened silently. An export taken while it was detached goes stale the moment it returns, and no hook was told. before_attach fires once its subtree is complete and before it takes rows (raising leaves it detached for the next run); after_attach fires when it is live.

Four other phases were considered and left out, and the reasons are in the commit message: a maintenance start/finish would force partition to be optional and saves a caller two lines; per-bucket calls would break the once-per-lifecycle-unit rule the plan already covers better; a failure callback observes what result.issues reports and cannot influence it; row-movement progress is a different concern with a different shape. None is closed off — a phase is now an enum value plus a no-op on the base class.

Why break in a minor

Semver says 2.0.0. The library is days old with nothing depending on it, and the alternative was carrying the split until a major — years, for an API that is wrong now. The changelog says exactly this and carries the before/after table for each method. Note for whoever cuts the release: the commits are deliberately feat: and not feat!:, or release-please would take this to 2.0.0.

Failing loudly instead of at 3am

A runtime-checkable protocol only asks whether an attribute exists, so an unported hook would be accepted at wiring time and raise at its first call — mid-run, after some DDL had committed. Hook signatures are now read when the service is constructed, and a 1.0-shaped method is refused there, naming the class, the method and the shape to move to. Anything whose signature cannot be read (mocks, *args, C callables) is left alone rather than guessed at.

Checks

ruff, mypy, 2 515 unit tests and the whole integration suite (536) green locally on PostgreSQL 17, and in CI on 15, 16 and 17; the docs site builds. Migration table in the changelog; archiving guide, recipes, README and the agent page are ported.

The last of the three settings issue #27 found that could disagree without
anyone noticing. A timestamp or date key renders its bounds with no offset, so
reading one back means resolving it in some timezone, and only the zone it was
written under gives the same instant. With neither the provider's ddl_timezone
nor a table's boundaries to say what that was, the server's session default
decides and is_partition_closed can answer hours early or late, silently. It
now says so, once it has the literal in hand and can see there is a question --
a timestamptz bound carries its offset and never triggers it, and neither does
a zone the caller pinned either way.

is_naive_timestamp_literal lives beside the parser that already knows these
shapes. The roadmap records the other half of #27: giving the three
name-only hooks the same PartitionInfo their siblings get, which breaks every
hook at call time and so waits for the next major, with DropPartition.bounds
carrying the information through the plan until then.
@codecov

codecov Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.00990% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pg_partsmith/partition_bounds.py 88.88% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Three of the six phases were handed a rich object and three a bare string. A
before_drop that archived a partition got a name and nothing else -- and could
not look the rest up either, because DETACH clears relpartbound, so by drop
time the database no longer records where the partition sat. The split was an
accident of how the phases grew, and it showed: the config a hook needs was
passed to create hooks only, and an audit or metrics hook could not be written
at all except as six identical delegating methods.

Every hook method now takes one PartitionEvent: the phase, the config, the
partition, the window it covers, and the planned operation -- with the reason
it is in the plan and the size the policy measured. Where the window cannot be
known it is None rather than guessed. on_event is new and fires for every
phase in addition to the method named for it, so the cross-cutting cases are
one method that a later phase extends rather than breaks.

The two executor entry points and the two service methods that took a bare
table name now take the config the event is built from, which is what every
other entry point already took.

This breaks every hook written against 1.0, in a minor version, deliberately:
the library is days old and has no dependants to protect, and the alternative
was carrying the split until a major. Because a runtime-checkable protocol only
asks whether an attribute exists, an unported hook would otherwise be accepted
at wiring time and fail at its first call, mid-run, after some DDL had
committed -- so hook signatures are read when the service is constructed and a
1.0-shaped method is refused there, naming the class, the method and what to
move to. The changelog carries the before/after table.

Refs #27.
@AlexeyShalaev AlexeyShalaev changed the title Close the last silent disagreement from #27, and record what waits for 2.0 One event for every lifecycle hook, and the last silent disagreement from #27 Sep 1, 2026
An interrupt is not swallowed while reading a boundary literal, and a hook
method whose signature cannot be read is left alone rather than guessed at.
Both are one line of defensive code each and neither had a test.
A partition retention released is re-attached when its window is wanted again
-- retention grew, or create-ahead reached back to it -- and that transition
happened silently. Anything derived from the partition while it was out of the
tree, an export or a cold copy, goes stale the moment it returns, and no hook
was told.

before_attach fires once its subtree is complete and before it takes rows, so
raising there leaves the relation detached for the next run to plan again;
after_attach fires when it is live. Both carry the same event as every other
phase, with the AttachPartition operation and its reattach reason on it.

Four other phases were considered and left out. A maintenance start and finish
would force the event's partition to be optional, weakening every phase that
has one, to save a caller two lines around maintain(). Per-bucket calls would
break the rule that a hook fires once per lifecycle unit -- an export wants the
whole week, not one call per hash bucket -- and the plan already carries every
operation for anyone who wants that fidelity. A failure callback would observe
what result.issues already reports and cannot influence. Row-movement progress
is a different concern with a different shape. None of them is closed off: a
phase is now an enum value and a no-op on the base class.
Signature validation had a false positive and a false negative. A hook using
functools.singledispatchmethod reports (self, event) even when bound, so
judging by arity alone refused a hook written exactly right; a method taking no
event at all passed and failed at its first call. Both are gone: a leading self
or cls is dropped, then the signature is asked whether it can be called with
one event, which accepts (event), (*args) and (event, extra=None) alike.

on_event now runs before the method named for the phase. It used to run after,
so a before_* hook that refused an operation by raising left an audit trail
with nothing in it -- the one case an audit hook most wants recorded.

An attach is counted before after_attach fires, as a creation already was, so a
failing notification no longer makes the result disagree with the database.
(detach and drop have the same shape and count after their hook; that is 1.0
behaviour and needs the tally to move into the executor's own methods, so it is
left for its own change.)

The three event builders take the config: DEFAULT bounds say nothing about the
parent's method -- every method may have one -- and were reported as RANGE, so
a DEFAULT member of a LIST root lied about its parent. _parent_method now
answers None where the bounds do not say and the configured root decides. The
attach event also names how the partition will divide its own children, which
it knew from the operation and threw away.

is_naive_timestamp_literal no longer reads reduced ISO forms as timestamps:
"2024-01", "2024-W01" and "2024-001" are values a text or encoded key really
has, and they were drawing a timezone warning meant for real timestamps.

Docs: the ported hook example in the agent page still called the old parameter,
three places still showed the table-name argument these methods no longer take,
and the README example annotated a type it did not import. Four integration
call sites were still passing a table name where the config now goes -- they
only worked because no hooks were registered there.

Refs #27.
@AlexeyShalaev
AlexeyShalaev merged commit e7dde5e into master Sep 1, 2026
9 checks passed
@AlexeyShalaev
AlexeyShalaev deleted the fix/naive-bound-without-a-timezone branch September 1, 2026 16:23
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.

1 participant