diff --git a/hive/CHANGELOG.md b/hive/CHANGELOG.md index 9527d73a9..3e89ee8b6 100644 --- a/hive/CHANGELOG.md +++ b/hive/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.0+3 + +### Fixes +- Fixed bug where `object.save()` would faild on subsequent calls + ## 1.1.0+2 ### Fixes diff --git a/hive/lib/src/box/keystore.dart b/hive/lib/src/box/keystore.dart index 303ddc4d1..adf764472 100644 --- a/hive/lib/src/box/keystore.dart +++ b/hive/lib/src/box/keystore.dart @@ -121,7 +121,8 @@ class Keystore { if (deletedFrame != null) { _deletedEntries++; - if (deletedFrame.value is HiveObject) { + if (deletedFrame.value is HiveObject && + !identical(deletedFrame.value, frame.value)) { unloadHiveObject(deletedFrame.value as HiveObject); } } diff --git a/hive/pubspec.yaml b/hive/pubspec.yaml index 7daaaecbe..b2065ef6c 100644 --- a/hive/pubspec.yaml +++ b/hive/pubspec.yaml @@ -1,6 +1,6 @@ name: hive description: Lightweight and blazing fast key-value database written in pure Dart. Stronly encrypted using AES-256. -version: 1.1.0+2 +version: 1.1.0+3 author: Simon Leier homepage: https://github.com/hivedb/hive diff --git a/hive/test/keystore_test.dart b/hive/test/keystore_test.dart index 4740d3b3c..fed2fe0d6 100644 --- a/hive/test/keystore_test.dart +++ b/hive/test/keystore_test.dart @@ -193,7 +193,7 @@ void main() { var box = BoxMock(); var keystore = Keystore.debug(box: box); - var hiveObject = HiveObjectMock(); + var hiveObject = _TestHiveObject(); keystore.insert(Frame('key', hiveObject)); keystore.insert(Frame('key', HiveObjectMock())); @@ -201,6 +201,18 @@ void main() { expect(hiveObject.box, null); }); + test('does not unload HiveObject if it is the same instance', () { + var box = BoxMock(); + var keystore = Keystore.debug(box: box); + + var hiveObject = _TestHiveObject(); + keystore.insert(Frame('key', hiveObject)); + keystore.insert(Frame('key', hiveObject)); + + expect(hiveObject.key, 'key'); + expect(hiveObject.box, box); + }); + test('increases deletedEntries', () { var keystore = Keystore.debug(); expect(keystore.deletedEntries, 0);