-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Bug report) Relation map crashes when there is an unpaired relation definition #3055
Comments
Turns out the explaination is quite simple: Previously, we defined a single relation definition, having an inverse relation. The documentation says:
The problem is we didn't add the corresponding inverse relation. With just Adding the full declaration:
And then relation map will render like a charm. Nevertheless, even if the user somehow ends up with a inverse relation with no corresponding relation, the relation map should not crash. |
My attempts at a possible solution: Change the client to add a fake inverse relation: diff --git a/src/public/app/widgets/type_widgets/relation_map.js b/src/public/app/widgets/type_widgets/relation_map.js
index 615b9d06..2eeb0ed3 100644
--- a/src/public/app/widgets/type_widgets/relation_map.js
+++ b/src/public/app/widgets/type_widgets/relation_map.js
@@ -250,6 +250,7 @@ export default class RelationMapTypeWidget extends TypeWidget {
if (match) {
match.type = relation.type = relation.name === data.inverseRelations[relation.name] ? 'biDirectional' : 'inverse';
relation.render = false; // don't render second relation
+ data.inverseRelations[match.name] = relation.name;
} else {
relation.type = 'uniDirectional';
relation.render = true; or, change the server to add a fake inverse relation: diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js
index ccd6dec0..bb493530 100644
--- a/src/routes/api/notes.js
+++ b/src/routes/api/notes.js
@@ -181,6 +181,7 @@ function getRelationMap(req) {
if (def.inverseRelation) {
resp.inverseRelations[relationDefinition.getDefinedName()] = def.inverseRelation;
+ resp.inverseRelations[def.inverseRelation] = relationDefinition.getDefinedName();
}
}
} Both of these result in a working diagram: |
Here are my notes more detailed notes regarding this issue: Relation map crashes when there is an unpaired relation definition.zip Please note that this does not contain the notes that have this issue. Interestingly enough, attempting to export and then importing the notes into a clean environment will not reproduce the issue. It has to be done manually as per the steps above. |
Fix relation map crash on missing inverse pair (fixes #3055)
Trilium Version
0.54.2
What operating system are you using?
Other Linux
What is your setup?
Local (no sync)
Operating System Version
Linux workstation 5.10.135 #1-NixOS SMP Wed Aug 3 10:00:52 UTC 2022 x86_64 GNU/Linux
Description
Steps to reproduce:
contains
containedIn
#relation:contains(inheritable)="promoted,multi,inverse=containedIn"
~contains=Child 1 ~contains=Child2 ~contains=Child3
The diagram gets half-rendered:
The console reveals this stack trace:
The text was updated successfully, but these errors were encountered: