hive icon indicating copy to clipboard operation
hive copied to clipboard

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

Open minoesteban opened this issue 2 years ago • 8 comments

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

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

// Initialization 
Future<void> 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<void> 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

minoesteban avatar May 29 '23 15:05 minoesteban

I think you should add adapterName like that issue

MohamedAboElM3aTy avatar May 30 '23 21:05 MohamedAboElM3aTy

Could you elaborate on the need for that extra parameter for a solution here? It seems that if not set a default one is created, that is already unique to each adapter

minoesteban avatar Jun 01 '23 06:06 minoesteban

Same here, i faced this after upgrading flutter 3.10.2

umutbariscoskun avatar Jun 01 '23 10:06 umutbariscoskun

Any update on this?!

AliEasy avatar Aug 05 '23 14:08 AliEasy

deleteFromDisk() and open again

BoBoSama avatar Sep 14 '23 03:09 BoBoSama

Try add ignoreTypeId before registerAdapter

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

waslost0 avatar Nov 03 '23 05:11 waslost0

I'm also facing this issue with Flutter version 3.16.9

LaxmikanthMadhyastha avatar Mar 06 '24 15:03 LaxmikanthMadhyastha