From f7cddd3f20e009ab8ec298d5c2ad1da01313830d Mon Sep 17 00:00:00 2001 From: Suhrid Marwah Date: Sat, 11 Apr 2026 04:32:24 +0530 Subject: [PATCH 1/2] fix(notifications): handle limit=0 in getNotifications query Replace falsy guards with explicit undefined checks so that a limit or offset of 0 is not silently discarded. Signed-off-by: Suhrid Marwah --- .../src/database/DatabaseNotificationsStore.test.ts | 5 +++++ .../src/database/DatabaseNotificationsStore.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index d8ae3faf57..429aea4f3d 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -469,6 +469,11 @@ describe.each(databases.eachSupportedId())( id3, ]); }); + + it('should return empty array when limit is 0', async () => { + const result = await storage.getNotifications({ user, limit: 0 }); + expect(result).toEqual([]); + }); }); describe('getNotifications sorting', () => { diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index 5bed0c7674..6ebd64f4f4 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -289,11 +289,11 @@ export class DatabaseNotificationsStore implements NotificationsStore { } } - if (options.limit) { + if (options.limit !== undefined) { query.limit(options.limit); } - if (options.offset) { + if (options.offset !== undefined) { query.offset(options.offset); } From 070af4230736479e9c985625ade435653c66a9f5 Mon Sep 17 00:00:00 2001 From: suhr25 Date: Sun, 12 Apr 2026 15:50:35 +0530 Subject: [PATCH 2/2] Add changeset for notifications limit=0 fix Signed-off-by: suhr25 --- .changeset/fix-notifications-limit-zero.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fix-notifications-limit-zero.md diff --git a/.changeset/fix-notifications-limit-zero.md b/.changeset/fix-notifications-limit-zero.md new file mode 100644 index 0000000000..4f30fc0394 --- /dev/null +++ b/.changeset/fix-notifications-limit-zero.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-notifications-backend': patch +--- + +Fix handling of `limit=0` in `getNotifications` query to return empty results instead of all notifications