AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

SQL Editor: “Rename With Supabase AI” Returns Valid Title But Does Not Update The Name Field

The AI rename feature in the Supabase Dashboard SQL Editor fetches a valid title and description from the AI endpoint, but the Name field in the Rename dialog remains unchanged after the loading state finishes.

mediumConfidence 85%React

Origin Analysis

The AI endpoint returns the field `title`, but the client-side Rename dialog expects a field named `name`. The handler likely assigns the response to the wrong state key (e.g., `response.name`) or fails to map `response.title` to the name input state, leaving the Name field unchanged.
1. Open a query containing SQL in the SQL Editor. 2. Open the “Rename query” dialog. 3. Click “Rename with Supabase AI”. 4. Wait for the loading state to finish. 5. Observe that the Name field remains unchanged even though the network response contains a valid title.

Fixing Code Block

const onRenameWithAI = async () => { setIsLoading(true); try { const response = await fetch('/dashboard/api/ai/sql/title-v2', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sql: snippet.content.sql }), }); if (!response.ok) throw new Error('AI rename failed'); const data = await response.json(); // Map API response fields to local form state if (typeof data.title === 'string' && data.title.length > 0) { setName(data.title); } if (typeof data.description === 'string' && data.description.length > 0) { setDescription(data.description); } } catch (error) { console.error(error); // Optionally surface an error toast to the user } finally { setIsLoading(false); } };
The handler now explicitly maps the API response field `title` to the component's `name` state using `setName(data.title)`, and similarly maps `description` to `setDescription(data.description)`. Guard clauses ensure that only non-empty strings overwrite existing values, and the `finally` block guarantees the loading state is cleared even on error.

Edge Case Audit

If the AI endpoint changes its response schema (e.g., renames `title` to `name`), this mapping will break again. The guard clauses prevent overwriting existing values with `undefined` or empty strings, but a user who manually typed a name before clicking AI may not get it overwritten if the AI returns an empty title. Ensure error handling is connected to a user-visible notification if the request fails. Rollback: revert to the previous handler implementation.

Ecosystem Topology