Repository navigation
REST: deleting by filter has no limit and is permanent by default #32094
Replies: 3 comments
|
Kind: probable REST API bug. A filter-based delete has no reported record limit and can permanently remove every match. |
|
I investigated this in // packages/twenty-server/src/engine/twenty-orm/repository/workspace-repository.ts:1224
if (kind === 'update' && recordsBefore.length > QUERY_MAX_RECORDS) {
throw new TwentyOrmException(
`Cannot update more than ${QUERY_MAX_RECORDS} records at once`,
TwentyOrmExceptionCode.TOO_MANY_RECORDS_TO_UPDATE,
...
);
}The check only guards Adding I have verified this and prepared a clean fix with unit tests on branch |
|
Please discuss this with product since this seems to be an intentional behavior |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Bug Description
DELETE /rest/companies?filter=…deletes every matching record in one request. In my test a filter that matched 311 companies deleted all of them. Updating by filter is limited to 200 records ("Cannot update more than 200 records at once"), and so is a batch create, but a delete has no limit.REST deletes are also permanent unless
soft_delete=trueis sent. The records do not go to the trash and cannot be restored. In the app and with GraphQL'sdeleteCompany, a delete moves records to the trash, so the same action does two different things.Steps to reproduce, with an API key:
Cleanup test 1…Cleanup test 300, for example with twoPOST /rest/batch/companiesrequests of 150 eachPATCH /rest/companies?filter=name[like]:"Cleanup test%"with{"address": {"addressCity": "Sofia"}}is refused:400 "Cannot update more than 200 records at once"DELETE /rest/companies?filter=name[like]:"Cleanup test%"answers200, anddeleteCompanieslists all 300 recordsGET /rest/companies?filter=and(name[like]:"Cleanup test%",deletedAt[is]:NOT_NULL)returnstotalCount: 0: none of them is in the trash, so they cannot be restoredExpected behavior
As it is, a small mistake in a filter can wipe data with no way back.
Technical inputs
soft_deletedefault is documented in the OpenAPI spec, so it may be intended. I'm reporting it because of the missing limit and the difference with the app.All reactions