From 83263dc5808dfdcfefb426308d770471940d6b05 Mon Sep 17 00:00:00 2001
From: Drew McLellan
Date: Mon, 30 Nov 2026 16:31:21 +0000
Subject: [PATCH] fix(studio): give downloadable backups their own query key
(FE-5243)
useDownloadableBackupQuery and useBackupsQuery shared one query key for two
different endpoints. The failed restore screen mounts both, so one could
read the other's data: Download backup used the wrong list.
Split the key, restore the original support copy so it stays accurate when
no retry is offered, and drop the local `common` mock from the new test in
favor of the harness auth context. Add a test for the screen that fails
when the key is shared again.
---
.../ProjectLayout/RestoreFailedState.tsx | 2 +-
.../RetryFailedRestore.platform.test.tsx | 69 ++++++++++++++++---
apps/studio/data/database/backup-query.ts | 2 +-
apps/studio/data/database/keys.ts | 2 +
4 files changed, 65 insertions(+), 10 deletions(-)
diff --git a/apps/studio/components/layouts/ProjectLayout/RestoreFailedState.tsx b/apps/studio/components/layouts/ProjectLayout/RestoreFailedState.tsx
index 94e1969a62d..109bcc109ef 100644
--- a/apps/studio/components/layouts/ProjectLayout/RestoreFailedState.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/RestoreFailedState.tsx
@@ -84,7 +84,7 @@ export const RestoreFailedState = () => {
here.
- Retry the restore, or contact support for assistance.
+ Please contact support for assistance.
diff --git a/apps/studio/components/layouts/ProjectLayout/RetryFailedRestore.platform.test.tsx b/apps/studio/components/layouts/ProjectLayout/RetryFailedRestore.platform.test.tsx
index b592b846563..dc3ed80dfc3 100644
--- a/apps/studio/components/layouts/ProjectLayout/RetryFailedRestore.platform.test.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/RetryFailedRestore.platform.test.tsx
@@ -3,9 +3,11 @@ import userEvent from '@testing-library/user-event'
import { platformComponents as components } from 'api-types'
import { mockAnimationsApi } from 'jsdom-testing-mocks'
import { HttpResponse } from 'msw'
-import { describe, expect, test, vi } from 'vitest'
+import { describe, expect, test } from 'vitest'
+import { RestoreFailedState } from './RestoreFailedState'
import { RetryFailedRestore } from './RetryFailedRestore'
+import { createMockAuthContext } from '@/tests/lib/auth-helpers'
import { customRender } from '@/tests/lib/custom-render'
import { addAPIMock } from '@/tests/lib/msw'
import { NO_PERMISSIONS } from '@/tests/lib/permissions-fixtures'
@@ -14,11 +16,7 @@ import { mockProjectGrantContext } from '@/tests/lib/project-grant-mocks'
type BackupsResponse = components['schemas']['BackupsResponse_Output']
type Backup = BackupsResponse['backups'][number]
-
-vi.mock('common', async () => {
- const actual = await vi.importActual>('common')
- return { ...actual, useIsLoggedIn: () => true, useParams: () => ({ ref: 'default' }) }
-})
+type DownloadableBackupsResponse = components['schemas']['DownloadableBackupsResponse_Output']
mockAnimationsApi()
@@ -65,8 +63,12 @@ const clickRetryRestore = async () => {
fireEvent.click(button)
}
-const renderComponent = () =>
- customRender(, { profileContext: createMockProfileContext() })
+const renderOptions = {
+ authContext: createMockAuthContext(),
+ profileContext: createMockProfileContext(),
+}
+
+const renderComponent = () => customRender(, renderOptions)
describe('RetryFailedRestore', () => {
test('retries the restore from the latest completed physical backup by default', async () => {
@@ -135,4 +137,55 @@ describe('RetryFailedRestore', () => {
expect(await screen.findByRole('button', { name: 'Retry restore' })).toBeAriaDisabled()
})
+
+ // The screen also loads the downloadable backups: a different list, from a different endpoint
+ test('keeps both backup lists separate on the failed restore screen', async () => {
+ mockProjectGrantContext({ ref: 'default' })
+ addAPIMock({
+ method: 'get',
+ path: '/platform/organizations/:slug/billing/subscription',
+ response: {
+ addons: [],
+ billing_via_partner: false,
+ current_period_end: 1700000000,
+ current_period_start: 1700000000,
+ next_invoice_at: 1700000000,
+ payment_method_type: 'card',
+ plan: { id: 'pro', name: 'Pro' },
+ project_addons: [],
+ usage_billing_enabled: false,
+ },
+ })
+ mockBackups([createBackup({ id: 1, inserted_at: '2026-11-20T03:00:00.000Z' })])
+ addAPIMock({
+ method: 'get',
+ path: '/platform/database/:ref/backups/downloadable-backups',
+ response: () =>
+ HttpResponse.json({
+ status: 'ok',
+ backups: [createBackup({ id: 99, isPhysicalBackup: false })],
+ }),
+ })
+ const downloads: unknown[] = []
+ addAPIMock({
+ method: 'post',
+ path: '/platform/database/:ref/backups/download',
+ response: async ({ request }) => {
+ downloads.push(await request.json())
+ return HttpResponse.json<{ fileUrl: string }>({ fileUrl: '#backup' })
+ },
+ })
+
+ customRender(, renderOptions)
+
+ expect(await screen.findByRole('combobox', { name: 'Backup' })).toHaveTextContent(
+ '20 Nov 2026 03:00:00 (UTC)'
+ )
+
+ const downloadButton = screen.getByRole('button', { name: 'Download backup' })
+ await waitFor(() => expect(downloadButton).not.toBeAriaDisabled())
+ fireEvent.click(downloadButton)
+
+ await waitFor(() => expect(downloads).toEqual([{ id: 99 }]))
+ })
})
diff --git a/apps/studio/data/database/backup-query.ts b/apps/studio/data/database/backup-query.ts
index cabb1bd50fc..32cbc21d7fa 100644
--- a/apps/studio/data/database/backup-query.ts
+++ b/apps/studio/data/database/backup-query.ts
@@ -36,7 +36,7 @@ export const useDownloadableBackupQuery = (
}: UseCustomQueryOptions = {}
) =>
useQuery({
- queryKey: databaseKeys.backups(projectRef),
+ queryKey: databaseKeys.downloadableBackups(projectRef),
queryFn: ({ signal }) => getDownloadableBackup({ projectRef }, signal),
enabled: enabled && typeof projectRef !== 'undefined',
...options,
diff --git a/apps/studio/data/database/keys.ts b/apps/studio/data/database/keys.ts
index 9ff1df0470e..c55a5f62230 100644
--- a/apps/studio/data/database/keys.ts
+++ b/apps/studio/data/database/keys.ts
@@ -35,6 +35,8 @@ export const databaseKeys = {
['projects', projectRef, 'view-definition', id, includeCreateStatement ?? false] as const,
backups: (projectRef: string | undefined) =>
['projects', projectRef, 'database', 'backups'] as const,
+ downloadableBackups: (projectRef: string | undefined) =>
+ ['projects', projectRef, 'database', 'downloadable-backups'] as const,
poolingConfiguration: (projectRef: string | undefined) =>
['projects', projectRef, 'database', 'pooling-configuration'] as const,
indexesFromQuery: (projectRef: string | undefined, query: string) =>