Skip to content

IllegalArgumentException: Duplicate Key thrown for two relationships with different direction #2918

Closed
@ma-ku

Description

@ma-ku

We have a simple model that contains Failure nodes than CAUSE other Failure nodes when a particular Condition is met. To avoid circular dependencies and potential full loading of the graph, we only provide relations on the condition node rather than having the inverse relation defined at the Failure node.

Since we are interested into upstream and downstream failures, we have two relationships defined which of course use the same type CAUSE but have opposite directions.

After a completely detached change in another portion of the codebase we started receiving above error for the relationship between Condition and Failure:

IllegalArgumentException: Duplicate key 'ConditionNode_CAUSES_FailureNode'

After debugging the issue we found out that the type of Cypher statement that is created depends upon the fact if the graph could contain cycles. After our latest change, the graph became cycle-free and the generated uses a different generator strategy that leads to above error. We have implemented a tiny change that would overcome the issue. In class RelationshipDescription of SDN, the method below must return different names depending on the direction of the relationship:

@NonNull
default String generateRelatedNodesCollectionName(NodeDescription<?> mostAbstractNodeDescription) {

       if (this.isOutgoing()) {
		return this.getSource().getMostAbstractParentLabel(mostAbstractNodeDescription) + "_" + this.getType() + "_" + this.getTarget().getPrimaryLabel();
	} else {
		return this.getTarget().getPrimaryLabel() + "_" + this.getType() + "_" + this.getSource().getMostAbstractParentLabel(mostAbstractNodeDescription);
	}
}

I have created a branch in my fork of SDN that provides a test cases that covers that issue.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions