Skip to content

fix(databases): clone enum elements to prevent mutation on cancel#3129

Open
okxint wants to merge 1 commit into
appwrite:mainfrom
okxint:fix/enum-elements-mutation-on-cancel
Open

fix(databases): clone enum elements to prevent mutation on cancel#3129
okxint wants to merge 1 commit into
appwrite:mainfrom
okxint:fix/enum-elements-mutation-on-cancel

Conversation

@okxint

@okxint okxint commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #2245

Problem

The attribute edit dialog used a shallow spread ({ ...selectedColumn }) to initialize a local copy, but the elements array inside was still shared by reference. Editing enum values in the dialog mutated the original source object immediately, so clicking Cancel had no effect — the changes were already written to the parent's data.

Fix

Introduce a deepCloneColumn() helper that spreads the column and copies elements with [...col.elements]. On dialog open, both editingColumn and currentColumn are deep-cloned from selectedColumn. All form inputs and child components bind to editingColumn — the original selectedColumn is never touched until submit() sends the cloned data to the API. On cancel/close, editingColumn is set to null, discarding all edits.

Editing enum column elements in the edit dialog mutated the source
object in place because the form bound directly to selectedColumn.
Introduce editingColumn as a deep-cloned local copy on dialog open so
cancelled edits are discarded without touching the original data.
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR isolates database column edits from the selected source column. The main changes are:

  • Adds a local cloned editingColumn state.
  • Copies enum elements before editing.
  • Sends the cloned column on update.
  • Compares the clone against the original clone for dirty-state checks.

Confidence Score: 5/5

This looks safe to merge after a small stale-state cleanup.

  • The main cancel behavior is fixed by editing a cloned column.
  • A reused open sheet can keep the previous cloned column if the selection changes while it remains open.

src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte

Important Files Changed

Filename Overview
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte Moves column edit bindings and submit payloads from selectedColumn to a cloned local edit object.

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte:120-122
**Open Sheet Keeps Stale Column**

When the edit sheet is already open and `selectedColumn` changes without a `showEdit` false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.

Reviews (1): Last reviewed commit: "fix(databases): clone enum elements arra..." | Re-trigger Greptile

Comment on lines 120 to +122
if (show) {
currentColumn ??= { ...selectedColumn };
editingColumn = deepCloneColumn(selectedColumn);
currentColumn ??= deepCloneColumn(selectedColumn);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Open Sheet Keeps Stale Column

When the edit sheet is already open and selectedColumn changes without a showEdit false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte
Line: 120-122

Comment:
**Open Sheet Keeps Stale Column**

When the edit sheet is already open and `selectedColumn` changes without a `showEdit` false transition, this path does not refresh the cloned edit state or the original key. The next update can submit the previous column clone while the UI state points at a different selected column, which can update or rename the wrong column.

How can I resolve this? If you propose a fix, please make it concise.

Fix in Claude Code Fix in Codex

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Collection attributes: Enum elements update without clicking "update"

1 participant