Skip to content

fix: guard against undefined table in updateKeyName - #3141

Open
okxint wants to merge 1 commit into
appwrite:mainfrom
okxint:fix/update-key-name-null-guard
Open

fix: guard against undefined table in updateKeyName#3141
okxint wants to merge 1 commit into
appwrite:mainfrom
okxint:fix/update-key-name-null-guard

Conversation

@okxint

@okxint okxint commented Jul 27, 2026

Copy link
Copy Markdown

Array.find() returns undefined when no table matches the selected relatedTable id (e.g. while the table list is still loading or the value was pre-populated from a saved state). Calling .name on undefined throws a runtime error.

Added an if (table) guard before accessing table.name.

tableList.tables.find() returns undefined when the selected table is
not yet in the loaded page or the list hasn't finished loading.
Dereferencing table.name without a null check caused a TypeError crash
when creating a relationship attribute.

Add an explicit guard so data.key is only updated when the table is found.
@greptile-apps

greptile-apps Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes relationship-column key derivation skip missing table lookup results.

  • Adds a presence check before reading the matched table's name.
  • Leaves the existing key unchanged when no table matches.

Confidence Score: 3/5

This PR should not merge until updateKeyName also handles an unavailable table list without throwing.

The new result guard prevents reading name from an absent match, but the same handler can still fail earlier by reading tables from the undefined list during asynchronous initialization.

Files Needing Attention: src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/relationship.svelte

Important Files Changed

Filename Overview
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/columns/relationship.svelte Guards a missing find() result, but still dereferences the asynchronously initialized table list before that guard.

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/relationship.svelte:112-113
**Table list remains unguarded**

When the related-table change event runs before the asynchronous table-list request completes, `tableList.tables` is dereferenced while `tableList` is undefined, causing a runtime error before the new missing-table guard is reached.

Reviews (1): Last reviewed commit: "fix: guard against undefined table in up..." | Re-trigger Greptile

Comment on lines 112 to +113
const table = tableList.tables.find((n) => n.$id === data.relatedTable);
data.key = camelize(table.name);
if (table) {

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.

P1 Table list remains unguarded

When the related-table change event runs before the asynchronous table-list request completes, tableList.tables is dereferenced while tableList is undefined, causing a runtime error before the new missing-table guard is reached.

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/relationship.svelte
Line: 112-113

Comment:
**Table list remains unguarded**

When the related-table change event runs before the asynchronous table-list request completes, `tableList.tables` is dereferenced while `tableList` is undefined, causing a runtime error before the new missing-table guard is reached.

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.

1 participant