Skip to content

Fix "Migration handler not found" after upgrading to 3.0.0 (3.0.1) - #47

Merged
dvejsada merged 2 commits into
masterfrom
claude/clever-maxwell-h72rx1
Oct 4, 2026
Merged

dvejsada merged 2 commits into
masterfrom
claude/clever-maxwell-h72rx1

Conversation

@dvejsada

@dvejsada dvejsada commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #46.

Cause

Releases before 3.0.0 set the config flow VERSION = 0.1, so every existing config entry is stored with version 0.1. Version 3.0.0 raised VERSION to 1 but added no async_migrate_entry. When Home Assistant loads an old entry, it sees the version mismatch, logs Migration handler not found for entry … for pid_departures, and leaves the entry in MIGRATION_ERROR. As a result, every board set up before 3.0.0 stops loading. New installs are not affected.

Changes

  • __init__.py: add a versioned async_migrate_entry with debug logging:
    • 0.1 → 1.1: raise the version only. The stored data has not changed since 2.x.
    • 1.1 → 1.2: give entries without a unique ID the stop ID as unique ID. If another entry already uses that stop ID, the entry is left without one. This step used to run in async_setup_entry on every setup and reload; it now runs once per entry.
    • Major version above 1 (a downgrade from a future release): refused, so the entry is not loaded with a format this code doesn't understand.
  • config_flow.py: add MINOR_VERSION = 2, so new entries are created at 1.2.
  • manifest.json: bump to 3.0.1.
  • Add a .gitignore for __pycache__/ and *.pyc.

Users already on 3.0.0

A failed migration doesn't write anything, so their old entries are still stored as version 0.1 with the original data. Boards added on 3.0.0 are stored as 1.1 and migrate to 1.2 without changes. Updating to 3.0.1 and restarting is enough. They should not delete and re-add their boards, since that would replace the existing entities.

Testing

Tested on Home Assistant 2026.2.3 with pytest-homeassistant-custom-component. The tests patch out async_setup_entry, so no API calls are made.

  • Reproduction: with the 3.0.0 code, a version 0.1 entry fails with Migration handler not found for entry x x B for pid_departures and state MIGRATION_ERROR, and its version stays 0.1.
  • With this change, all 7 cases pass:
    • A 2.x entry (0.1) ends up LOADED at 1.2, with unique ID = stop ID and its data unchanged.
    • Two 2.x entries for the same stop both load; one gets the unique ID and the other keeps none.
    • An entry created on 3.0.0 (1.1, with unique ID) migrates to 1.2 unchanged.
    • A 2.x entry whose stop was re-added on 3.0.0 loads and keeps no unique ID, so it doesn't collide with the re-added entry.
    • A current 1.2 entry loads without migration.
    • An entry with major version 2 ends in MIGRATION_ERROR.
    • The config flow declares version 1.2.

The repo has no test suite, so the tests are not included in this PR.

Notes

  • Once an entry has migrated to version 1, downgrading to 2.x will fail with a migration error. Any version migration has this one-way cost. Downgrading from 3.0.1 to 3.0.0 still works, because only the minor version differs.
  • Before this change, an entry left without a unique ID (because its stop was a duplicate) was rechecked on every load. Now the check runs once, so if the user later deletes the other entry, the remaining one stays without a unique ID.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LYz7Z1Ewux6CkjNqGF9rMJ

claude added 2 commits October 4, 2026 12:02
Releases before 3.0.0 declared the config flow VERSION as 0.1, so existing
entries are stored with that version. 3.0.0 raised VERSION to 1 without an
async_migrate_entry handler, so Home Assistant refused to load those entries
("Migration handler not found"). The stored data is unchanged, so the
migration only raises the entry version to 1.

Fixes #46

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LYz7Z1Ewux6CkjNqGF9rMJ
The backfill ran on every setup and reload. It is now the 1.1 -> 1.2 step of
async_migrate_entry (config flow MINOR_VERSION = 2), so it runs once per
entry. Entries with a newer major version are refused instead of loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LYz7Z1Ewux6CkjNqGF9rMJ
@dvejsada
dvejsada merged commit 8acf816 into master Oct 4, 2026
2 checks passed
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.

Migration error after upgrading integration to version 3.0.0

2 participants