isar / isar/hive

Removing fields from HiveObject causing app startup to freeze in production.

Open
#1,099 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Question**
Hive docs say that I can remove a Hive field as long as I do not use the field number again for any other field.

```text
Fields can be removed, as long as the field number is not used again in your updated class.
```

But after doing so, and running the app in production, the app is stuck on the start up/splash screen.

I have existing models in cache that contain the fields that I am not longer using, but according to the docs, those fields would just be ignored. Am I doing something wrong?

To fix this, I am required to clear both cache and storage. I am also using flutter_secure_storage for encrypting the hive boxes. I have had issue with secure storage before doing something similar, but I thought it was weird that right after I adjusted the models that this happened.

**Code sample**
As you can see, I commented out a few fields that I am no longer using. Doing this worked fine in debug mode, but when I ran it in release, I started having the issues stated above.
```dart
@freezed
abstract class Session extends HiveObject with _$Session {
@HiveType(typeId: 4, adapterName: 'SessionAdapter')
factory Session({
@HiveField(0) required int pid,
@HiveField(1) required int rid,
@HiveField(2) required DateTime dateTime,
@HiveField(3) int? sid,
@HiveField(4) required String service,
@HiveField(5) required int duration,
@Default(0) @HiveField(6, defaultValue: 0) int status,
@HiveField(7) String? notes,
@HiveField(8) DateTime? editDate,
@HiveField(9) required String description,
// @HiveField(10)
// String time;
@HiveField(11) required String facility,
@HiveField(12) required String patientName,
// @HiveField(13) String? sessionResponse,
// @Default(false) @HiveField(14, defaultValue: false) bool isQueued,
// @HiveField(15) SessionAction? sessionAction,
// @HiveField(16) String? dataToServer,
// @HiveField(17) String? sessionResponseType,
@Default(0) @HiveField(18, defaultValue: 0) int clinicianId,
}) = _Session;

// ignore: unused_element // private constructor used so hive can be used.
Session._();

factory Session.fromJson(Map json) =>
_$SessionFromJson(json);
}
```

**Version**
- Platform: Android
- Flutter version: 3.0.6-0.0.pre.1
- Hive version: ^1.1.0

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Session model and the Hive box-opening path used during Android app startup. Reproduce the field removal in a release build with existing cached data, then compare behavior with and without flutter_secure_storage encryption. Done means identifying whether the freeze comes from removed fields, encrypted storage, or startup handling, and documenting a reproducible fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
database, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.