Skip to content

ENG-2145 Utility function to discover importable relations and schemas before node import - #1301

Open
maparent wants to merge 1 commit into
eng-2146-bulk-convert-some-db-structures-to-crossapp-structures-asfrom
eng-2145-utility-function-to-discover-importable-relations-and
Open

ENG-2145 Utility function to discover importable relations and schemas before node import#1301
maparent wants to merge 1 commit into
eng-2146-bulk-convert-some-db-structures-to-crossapp-structures-asfrom
eng-2145-utility-function-to-discover-importable-relations-and

Conversation

@maparent

@maparent maparent commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

@linear-code

linear-code Bot commented Aug 17, 2026

Copy link
Copy Markdown

ENG-2145

@supabase

supabase Bot commented Aug 17, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@vercel

vercel Bot commented Aug 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
discourse-graph Skipped Skipped Aug 20, 2026 12:31pm

Request Review

@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from 71badcf to 97993ea Compare August 17, 2026 22:34
@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from 97993ea to 7bfedb4 Compare August 19, 2026 13:38
@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from 7bfedb4 to 9d2a93d Compare August 19, 2026 13:53
@maparent
maparent marked this pull request as ready for review August 19, 2026 14:07
@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from 9d2a93d to 828f8da Compare August 19, 2026 14:08

@devin-ai-integration devin-ai-integration Bot left a comment

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.

Devin Review found 2 potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment thread apps/roam/src/utils/discoverSharedRelations.ts
Comment thread apps/roam/src/utils/discoverSharedRelations.ts Outdated
@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from 828f8da to a2ee135 Compare August 19, 2026 14:25
@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from a2ee135 to 62c2310 Compare August 19, 2026 14:31
@maparent
maparent requested a review from mdroidian August 19, 2026 14:32
.select()
.in("id", [...nodeTypeSchemaIds]);
if (nsError) throw nsError;
if (!nodeTypeSchemaIds) throw new Error("Missing relation type schemas");

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.

Wrong variable being checked. nodeTypeSchemaIds is a Set which is always truthy, so this guard will never trigger. Should check dbNodeTypeSchemas instead:

if (!dbNodeTypeSchemas) throw new Error("Missing node type schemas");

This means if the database query fails silently or returns null, the code will continue with undefined and crash later when trying to iterate over it.

Suggested change
if (!nodeTypeSchemaIds) throw new Error("Missing relation type schemas");
if (!dbNodeTypeSchemas) throw new Error("Missing node type schemas");

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +158 to +160
triplesBySchemaId[
((c.reference_content ?? {}) as Record<string, number>)["relation_type"]
].push(c as Concept);

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.

Undefined array access will crash. If relation_type is undefined in the triple's reference_content, this accesses triplesBySchemaId[undefined] which returns undefined, then calls .push() on undefined causing a runtime error.

data.forEach((c) => {
  const relationType = ((c.reference_content ?? {}) as Record<string, number>)["relation_type"];
  if (relationType !== undefined && triplesBySchemaId[relationType]) {
    triplesBySchemaId[relationType].push(c as Concept);
  }
});
Suggested change
triplesBySchemaId[
((c.reference_content ?? {}) as Record<string, number>)["relation_type"]
].push(c as Concept);
const relationType = ((c.reference_content ?? {}) as Record<string, number>)["relation_type"];
if (relationType !== undefined && triplesBySchemaId[relationType]) {
triplesBySchemaId[relationType].push(c as Concept);
}

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from 62c2310 to e728391 Compare August 19, 2026 16:33
@maparent
maparent force-pushed the eng-2145-utility-function-to-discover-importable-relations-and branch from e728391 to 825652b Compare August 20, 2026 12:31

@mdroidian mdroidian left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See graphite's comments

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.

2 participants