@dataclass on MigrationError breaks drift error reporting (TypeError instead of MigrationDriftError) #244

Closed
opened 2026-07-22 17:44:30 +00:00 by Mark · 2 comments
Owner

Bug Report

Description

MigrationError base class in substrate/ledger/migrations.py:118 is decorated with @dataclass, which generates an __init__ that takes only self. Subclasses (MigrationDriftError, UnknownMigrationError, ChecksumMismatchError) call super().__init__(message), which fails because the dataclass __init__ doesn't accept a message argument.

Impact

When a pre-migration ledger.db is encountered (drift detection), instead of raising MigrationDriftError, the code raises:

TypeError: MigrationError.__init__() takes 1 positional argument but 2 were given

The db_migrate.py verify command (which catches MigrationDriftError) won't report drift properly, making the migration verification path effectively broken.

Reproduction Steps

  1. Have a pre-existing ledger.db file that predates the migration framework
  2. Run python -m substrate.ledger.db_migrate verify (or any code path that triggers MeshLedger.__init__() with an existing DB)
  3. Observe TypeError instead of the expected MigrationDriftError

Expected Behavior

Drift detection should raise MigrationDriftError (or a subclass) so the verification CLI can report the issue properly.

Actual Behavior

TypeError: MigrationError.__init__() takes 1 positional argument but 2 were given

Root Cause

@dataclass  # <-- line 118: auto-generates __init__(self) only
class MigrationError(Exception):
    """Base class for migration errors."""

The @dataclass decorator generates an __init__ that conflicts with the exception protocol. Subclasses call super().__init__(message), which fails.

Fix

Remove @dataclass from MigrationError (line 118). The subclasses set instance attributes manually already.

Discovered By

Post-deploy probe of issue #166 (DATA-004: Database Migration)

References

Kanban card: t_befb3f36 (QA board)

## Bug Report ### Description `MigrationError` base class in `substrate/ledger/migrations.py:118` is decorated with `@dataclass`, which generates an `__init__` that takes only `self`. Subclasses (`MigrationDriftError`, `UnknownMigrationError`, `ChecksumMismatchError`) call `super().__init__(message)`, which fails because the dataclass `__init__` doesn't accept a message argument. ### Impact When a pre-migration ledger.db is encountered (drift detection), instead of raising `MigrationDriftError`, the code raises: ``` TypeError: MigrationError.__init__() takes 1 positional argument but 2 were given ``` The `db_migrate.py verify` command (which catches `MigrationDriftError`) won't report drift properly, making the migration verification path effectively broken. ### Reproduction Steps 1. Have a pre-existing ledger.db file that predates the migration framework 2. Run `python -m substrate.ledger.db_migrate verify` (or any code path that triggers `MeshLedger.__init__()` with an existing DB) 3. Observe `TypeError` instead of the expected `MigrationDriftError` ### Expected Behavior Drift detection should raise `MigrationDriftError` (or a subclass) so the verification CLI can report the issue properly. ### Actual Behavior ``` TypeError: MigrationError.__init__() takes 1 positional argument but 2 were given ``` ### Root Cause ```python @dataclass # <-- line 118: auto-generates __init__(self) only class MigrationError(Exception): """Base class for migration errors.""" ``` The `@dataclass` decorator generates an `__init__` that conflicts with the exception protocol. Subclasses call `super().__init__(message)`, which fails. ### Fix Remove `@dataclass` from `MigrationError` (line 118). The subclasses set instance attributes manually already. ### Discovered By Post-deploy probe of issue #166 (DATA-004: Database Migration) ### References Kanban card: `t_befb3f36` (QA board)
Mark closed this issue 2026-08-04 04:34:57 +00:00
Author
Owner

QA reconciliation found the issue was closed without a landed fix. The prior QA run created local commit 07abae2 on branch fix/mesh-seed-244-dataclass-migrationerror, but neither commit nor branch exists on Forgejo. Current origin/master is 92521ce; substrate/ledger/migrations.py:118 still decorates MigrationError with @dataclass. Direct reproduction on that HEAD still raises TypeError: MigrationError.__init__() takes 1 positional argument but 2 were given. Reopening until the fix is pushed/merged and verified.

QA reconciliation found the issue was closed without a landed fix. The prior QA run created local commit `07abae2` on branch `fix/mesh-seed-244-dataclass-migrationerror`, but neither commit nor branch exists on Forgejo. Current `origin/master` is `92521ce`; `substrate/ledger/migrations.py:118` still decorates `MigrationError` with `@dataclass`. Direct reproduction on that HEAD still raises `TypeError: MigrationError.__init__() takes 1 positional argument but 2 were given`. Reopening until the fix is pushed/merged and verified.
Mark reopened this issue 2026-08-04 05:51:50 +00:00
Author
Owner

Fix pushed as PR #266 (#266). Single line change: remove @dataclass from MigrationError at line 118. Awaiting merge and verification.

Fix pushed as PR #266 (https://forgejo.tail018ac4.ts.net/Mark/mesh-seed/pulls/266). Single line change: remove `@dataclass` from `MigrationError` at line 118. Awaiting merge and verification.
Mark closed this issue 2026-08-04 17:06:34 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/mesh-seed#244
No description provided.