adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

After hook for bulkDelete action does not fire after the deletion if deletion fails

Open ryanillman opened this issue 3 years ago • 3 comments

Describe the bug When using after hooks with the bulkDelete action, the hook runs after the GET request that populates the confirmation modal/drawer is made, but not after the POST request that actually does the delete.

Installed libraries and their versions

To Reproduce Steps to reproduce the behavior:

  1. Add an after hook on a resource's bulk delete action that simply console.log()s when it runs
  2. Bulk delete some records for that resource that cannot be deleted due to a foreign key constraint
  3. The after hook will run when the list of records is returned to the frontend and the confirmation drawer is displayed
  4. The after hook does not run when the records are actually attempted to be deleted

Expected behavior The after hook runs after the delete takes place

ryanillman avatar Nov 29 '22 16:11 ryanillman

Can you show your after hook?

dziraf avatar Nov 30 '22 11:11 dziraf

The minimum I need to see the issue is just a console.warn:

const afterHook = (originalResponse, _request, _context) => {
  console.warn('in bulkDelete After Hook');
  return originalResponse
};

ryanillman avatar Nov 30 '22 23:11 ryanillman

Before running bulk delete (console output is on the left): image

After the GET request fires to list the to-be-deleted records, the hook is run: image

The hook does not run again after the POST, at least if the delete is not successful in the database: image

My goal is to be able to catch that error, and do something more useful with it.

Trying it now with records that can be deleted, the hook does run if the delete is successful. This is different than the non-bulk delete action, which runs the after hook even if the deletion fails.

ryanillman avatar Nov 30 '22 23:11 ryanillman