Skip to content

fix(api): await restoreDeletedId in snippet controllers - #678

Merged
pozsa merged 2 commits into
paulscherrerinstitute:mainfrom
knQzx:await-restore-deleted
Aug 20, 2026
Merged

pozsa merged 2 commits into
paulscherrerinstitute:mainfrom
knQzx:await-restore-deleted

Conversation

@knQzx

@knQzx knQzx commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

The snippet controllers called an async restore operation without awaiting it, so the response could return before the restore finished and any failure became an unhandled rejection. This awaits the call.

@knQzx
knQzx requested a review from a team as a code owner August 12, 2026 16:21
@pozsa

pozsa commented Aug 19, 2026

Copy link
Copy Markdown
Member

Thanks for catching this — the fix is correct and I'd like to merge it.

Would you be up for adding one regression test? The existing restore … should return 204 cases pass identically with and without the await, so nothing currently guards this. This one fails without your change and passes with it — I've run it on your branch:

it('restore a non-existent snippet id should return 404', async () => {
  await client
    .patch('/basesnippets/000000000000000000000000/restore')
    .set('Authorization', 'Bearer ' + token)
    .set('Content-Type', 'application/json')
    .expect(404);
});

It slots into api/src/__tests__/acceptance/basesnippet.controller.acceptance.ts next to the existing restore tests. Optional — if you'd rather not, I'll merge as-is and add it in a follow-up.

pozsa
pozsa previously approved these changes Aug 19, 2026
Without the await the rejected promise never reaches the request, so
restoring an unknown id answered 204 instead of 404.
@knQzx

knQzx commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

added it, thanks for writing it out and running it - it fails with 204 and passes with the await, exactly as you said.

i also put the same case in the location, logbook, paragraph and task acceptance files, since the fix touches those five controllers and only basesnippet would have been covered otherwise. happy to drop the extra four if you'd rather keep it to one.

@pozsa
pozsa added this pull request to the merge queue Aug 20, 2026
Merged via the queue into paulscherrerinstitute:main with commit 02d74c8 Aug 20, 2026
1 check passed
minottic pushed a commit that referenced this pull request Aug 20, 2026
## [2.11.4](v2.11.3...v2.11.4) (2026-08-20)

### Bug Fixes

* **api:** await restoreDeletedId in snippet controllers ([#678](#678)) ([02d74c8](02d74c8))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.11.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants