Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Improve error handling when updating row but table has no pk

Joshen Lim12a0785f94a9
diff --git a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index 8d158b7ecfd..56a81b2c554 100644
--- a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -35,6 +35,7 @@ import { ForeignRowSelectorProps } from './SidePanelEditor/RowEditor/ForeignRowS
import TwoOptionToggle from 'components/ui/TwoOptionToggle'
import TableDefinition from './TableDefinition'
import APIDocumentationPanel from './APIDocumentationPanel'
+import { ERROR_PRIMARY_KEY_NOTFOUND } from 'components/grid/constants'
export interface TableGridEditorProps {
/** Theme for the editor */
@@ -320,6 +321,12 @@ const TableGridEditor = ({
)
const configuration = { identifiers }
+ if (Object.keys(identifiers).length === 0) {
+ return ui.setNotification({
+ category: 'error',
+ message: ERROR_PRIMARY_KEY_NOTFOUND,
+ })
+ }
mutateUpdateTableRow({
projectRef: project.ref,
diff --git a/studio/data/table-rows/table-row-delete-mutation.ts b/studio/data/table-rows/table-row-delete-mutation.ts
index ec660bf90e2..c111a11c824 100644
--- a/studio/data/table-rows/table-row-delete-mutation.ts
+++ b/studio/data/table-rows/table-row-delete-mutation.ts
@@ -16,12 +16,9 @@ export function getTableRowDeleteSql({
rows,
}: Pick<TableRowDeleteVariables, 'table' | 'rows'>) {
const { primaryKeys, error } = getPrimaryKeys({ table })
- if (error) {
- throw error
- }
+ if (error) throw error
let queryChains = new Query().from(table.name, table.schema ?? undefined).delete()
-
primaryKeys!.forEach((key) => {
const primaryKeyValues = rows.map((x) => x[key])
queryChains = queryChains.filter(key, 'in', primaryKeyValues)