You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The deleteMany method in Realm Dart does not respect the _skipOffset when called on a RealmResults object that was modified using .skip(). As a result, it deletes all elements instead of only those that should be included after skipping.
Root Cause
The skip() method creates a new RealmResults with an internal _skipOffset.
The deleteMany implementation calls:
if (items isRealmResults<T>) {
_ensureManagedByThis(items, 'delete objects from Realm');
items.handle.deleteAll();
}
items.handle.deleteAll(); does not account for _skipOffset, leading to all items being deleted.
Expected Behavior
deleteMany(realm.all<Item>().skip(n)) should delete only the remaining items after skipping, not the entire collection.
Repro steps
Create an in-memory Realm instance.
Add two Item objects.
Call realm.all<Item>().skip(1), which returns a RealmResults with an internal _skipOffset.
Pass the result to deleteMany.
Expectation: The second item should be deleted, as skip(1) skips the first item and results in the second item being the only one left.
Actual behavior: deleteMany removes all items.
Version
Flutter 3.29.0 • Dart 3.7.0
What Atlas Services are you using?
Local Database only
What type of application is this?
Dart standalone application
Client OS and version
MacOS
Code snippets
@RealmModel()
class_Item {
@PrimaryKey()
lateint id;
}
voidmain() {
test('deleteMany should respect skip offset', () {
final realm =Realm(Configuration.inMemory([Item.schema]));
realm.write(() {
realm.add(Item(0));
realm.add(Item(1));
});
realm.write(() {
realm.deleteMany(realm.all<Item>().skip(1));
});
expect(realm.all<Item>().length, 1); // Fails: All items are deleted
realm.close();
});
}
The text was updated successfully, but these errors were encountered:
What happened?
The
deleteMany
method in Realm Dart does not respect the_skipOffset
when called on aRealmResults
object that was modified using.skip()
. As a result, it deletes all elements instead of only those that should be included after skipping.Root Cause
skip()
method creates a newRealmResults
with an internal_skipOffset
.deleteMany
implementation calls:items.handle.deleteAll();
does not account for_skipOffset
, leading to all items being deleted.Expected Behavior
deleteMany(realm.all<Item>().skip(n))
should delete only the remaining items after skipping, not the entire collection.Repro steps
Item
objects.realm.all<Item>().skip(1)
, which returns aRealmResults
with an internal_skipOffset
.deleteMany
.deleteMany
removes all items.Version
Flutter 3.29.0 • Dart 3.7.0
What Atlas Services are you using?
Local Database only
What type of application is this?
Dart standalone application
Client OS and version
MacOS
Code snippets
The text was updated successfully, but these errors were encountered: