isar / isar/hive

HiveError: Cannot read, unknown typeId: 34. Did you forget to register an adapter? when Removing an Adapter

Open
#1,207 8 comments 2 reactions 0 assignees View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Steps to Reproduce**
1. Create custom Adapter MainClass, create custom Adapter Property which is a property of A. Register
2. Write data
3. Remove adapter B
4. Read old data.

Reading fails with message `HiveError: Cannot read, unknown typeId: 34. Did you forget to register an adapter?`

Based on the docs, reading old data after removing a property should be safe, but it throws

Found another possible solution in this [comment](https://github.com/hivedb/hive/issues/332#issuecomment-639080192)

But we added `Hive.ignoreTypeId(N)` and now the error has changed, but it is still failing

The new error is `RangeError: Not enough bytes available.`

**Code sample**
```dart
// Initialization
Future initializeHive() async {
await Hive.initFlutter();

Hive.registerAdapter(MainClassAdapter());
Hive.registerAdapter(PropertyAdapter());
...
}

// Classes definition
@HiveType(typeId: 1)
class MainClass {
MainClass({
required this.property,
});
...
@HiveField(N)
final Property property;


@HiveType(typeId: 2)
class Property {
Property({required this.name});

@HiveField(0)
final String name;
}

// After writing some data with this structure,
// we removed Property from the registerAdapter calls, and form the MainClass definition

But we started getting HiveError: unknown typeId when reading old data

// Then, we tried with

// Initialization
Future initializeHive() async {
await Hive.initFlutter();

Hive.registerAdapter(MainClassAdapter());
Hive.ignoreTypeId(2);
...
}

// But now we get RangeError: Not enough bytes available.
```

**Version**
- Platform: iOS, Android
- Flutter version: 3.7.0
- Hive version: hive: 2.2.3, hive_flutter: 1.1.0, hive_generator: 2.0.0

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided adapter-registration and old-data reproduction using Hive 2.2.3, focusing on Hive.registerAdapter and Hive.ignoreTypeId. Verify behavior when a registered Property adapter is removed: reading existing MainClass data should not produce an unknown typeId or RangeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
databases, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.