Description:
When attempting to perform a bulk delete operation, the transaction consistently fails with the error Cannot assign to read-only property '_status'. This issue occurs even when using the recommended database.write and database.batch patterns.
Environment
- "@nozbe/watermelondb": "0.28.0",
- "react-native": "0.79.4",
- "expo": "53.0.12",
- Platform: [Android/iOS]
Expected Behavior
The database.write block should execute successfully, and all records in the deletedMedia array should be marked as deleted in a single atomic transaction.
Actual Behavior
The database.write block throws an exception: Cannot assign to read-only property '_status'. The console often logs this error for each item that was supposed to be deleted, and the operation is not completed successfully.
Code Example:
try {
await database.write(async () => {
const recordsToDelete = await database
.get('record_medias')
.query(Q.where('id', Q.oneOf(idsToDelete)))
.fetch();
const preparedDeletions = recordsToDelete.map(record => record.prepareMarkAsDeleted());
await database.batch(...preparedDeletions);
});
} catch (error) {
console.error('Failed to execute batch delete transaction', error);
}
Also I have tried to do something like this (not use batch), but I got the same result
try {
await database.write(async () => {
const recordsToDelete = await database
.get('record_medias')
.query(Q.where('id', Q.oneOf(idsToDelete)))
.fetch();
await Promise.all(
recordsToDelete.map(record => record.markAsDeleted())
);
});
} catch (error) {
console.error('Failed to execute batch delete transaction', error);
}
And also I tried to do next (call database,write each time for each item) but result also was thr same
await Promise.all(
mediaItems.map(mediaItem => {
if (!mediaItem) return
try {
await database.write(async () => {
await mediaItem.markAsDeleted()
})
} catch (error) {
logger.error('Failed to delete a exist record media to db', error)
}
})
)
Also I have tried to add delay between delete items, but result the same, only first item deleted and all other throw _status issue.
Description:
When attempting to perform a bulk delete operation, the transaction consistently fails with the error Cannot assign to read-only property '_status'. This issue occurs even when using the recommended database.write and database.batch patterns.
Environment
Expected Behavior
The database.write block should execute successfully, and all records in the deletedMedia array should be marked as deleted in a single atomic transaction.
Actual Behavior
The database.write block throws an exception: Cannot assign to read-only property '_status'. The console often logs this error for each item that was supposed to be deleted, and the operation is not completed successfully.
Code Example:
Also I have tried to do something like this (not use batch), but I got the same result
And also I tried to do next (call database,write each time for each item) but result also was thr same
Also I have tried to add delay between delete items, but result the same, only first item deleted and all other throw _status issue.