Deleting all merge requests belonging to a project

I migrated to GitLab from Github sometime now but recently I started seeing a pop-up window informing me that one of my projects exceeded the size 10GB and thus I am no longer able to push to it. I identified that this is the imported Unreal Engine source. I tried deleting the project but it kept reappearing. After playing around for a while I have got the following error message:

This project was scheduled for deletion, but failed with the following message: PG::QueryCanceled: ERROR: canceling statement due to statement timeout CONTEXT: SQL statement "UPDATE ONLY "public"."merge_requests" SET "source_project_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "source_project_id""

This gave me the hint that the problem was connected to the merge requests, so I wrote a script to use GitLab’s API to delete all the merge requests. I had to run it a few times as the connection was closed after about 1500 merge requests deleted, and the unreal source contains some 6000 merge requests. Deleting all the merge requests solved my issue, I could delete the project after my script completed but I am still wondering:

  • What is the preferred way of deleting all the merge requests belonging to a project?
  • What caused the issue in the first place? Is this a bug I should report?

Thank you for your help!

Edit: the script I used