Skip to content

fix: prevent TypeError when updating relationship attribute#2953

Open
jaydeep-pipaliya wants to merge 1 commit intoappwrite:mainfrom
jaydeep-pipaliya:fix-9951-relationship-attribute-update-crash
Open

fix: prevent TypeError when updating relationship attribute#2953
jaydeep-pipaliya wants to merge 1 commit intoappwrite:mainfrom
jaydeep-pipaliya:fix-9951-relationship-attribute-update-crash

Conversation

@jaydeep-pipaliya
Copy link
Copy Markdown

Summary

Fixes an uncaught TypeError that crashes the console when clicking "Update" on a relationship attribute from the three-dots menu in the columns list.

Root cause: Two places in edit.svelte access the option variable without null checks:

  1. Line 106 — The reactive title statement option.name throws TypeError: Cannot read property 'name' of undefined when the columnOptions.find() on line 37-52 doesn't match the selected column type
  2. Line 56option.update() would also crash if called when option is undefined

Fix:

  • Add a null guard on the title derivation: check option is defined before accessing .name
  • Add a null guard in submit(): throw a descriptive error ("Unsupported column type") instead of crashing with an unhandled TypeError

Fixes appwrite/appwrite#9951

Test plan

  • Go to a database collection with a relationship attribute
  • Click the three-dots menu on the relationship attribute
  • Click "Update" — the edit dialog should open without any console errors
  • Verify the dialog title renders correctly
  • Verify you can modify onDelete behavior and save
  • Verify non-relationship attributes (string, integer, enum) still update correctly

The edit dialog crashed with an uncaught TypeError when clicking
"Update" on a relationship attribute because the reactive title
statement accessed option.name without checking if option was
defined. The submit function also called option.update() without a
null guard.

Add null checks for option in both the title derivation and the
submit function to prevent the crash and show a proper error message.

Fix appwrite/appwrite#9951
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 1, 2026

Greptile Summary

This PR adds targeted null guards to edit.svelte to prevent an uncaught TypeError when the columnOptions.find() reactive statement returns undefined (e.g. for a relationship attribute) — a real regression that crashed the edit dialog.

  • submit() guard (line 56-58): Checks !option?.update before calling option.update(...) and throws a descriptive "Unsupported column type" error instead of crashing; the existing catch block surfaces this cleanly to the user.
  • Title expression (line 109): Wraps the option.name access in an option ? ternary so it no longer throws when option is undefined.
  • Minor redundancy: When option is defined it is already the result of columnOptions.find(...), so the nested columnOptions.find((v) => v.name === option.name) is a superfluous second scan — option.sentenceName is equivalent and simpler (P2 style suggestion left inline).

Confidence Score: 5/5

Safe to merge — targeted two-line fix with no new logic paths, only P2 style feedback remains.

Both changes are minimal and correct null guards that stop a real crash. No P0/P1 issues were found; the only observation is a trivial redundant find in the title expression that can be simplified to option?.sentenceName.

No files require special attention.

Important Files Changed

Filename Overview
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/edit.svelte Adds null guards for option in submit() and the reactive title expression, preventing a TypeError when editing a relationship attribute whose type doesn't match any columnOptions entry.

Reviews (1): Last reviewed commit: "fix: prevent TypeError when updating rel..." | Re-trigger Greptile

// TODO: @itznotabug - runes?
$: onShow(showEdit);
$: title = `Update ${columnOptions.find((v) => v.name === option.name)?.sentenceName ?? ''} column`;
$: title = `Update ${option ? (columnOptions.find((v) => v.name === option.name)?.sentenceName ?? '') : ''} column`;
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 Redundant find when option is already the matched entry

When option is defined, it is already the result of columnOptions.find(...), so searching columnOptions a second time by option.name to get sentenceName is redundant — you can read option.sentenceName directly. This simplifies the expression and avoids a linear scan:

Suggested change
$: title = `Update ${option ? (columnOptions.find((v) => v.name === option.name)?.sentenceName ?? '') : ''} column`;
$: title = `Update ${option?.sentenceName ?? ''} column`;

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: Uncaught TypeError when trying to update a relationship attribute

1 participant