Skip to content
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

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

Closed
ma-ku opened this issue Jul 5, 2024 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@ma-ku
Copy link
Contributor

ma-ku commented Jul 5, 2024

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 5, 2024
ma-ku added a commit to ma-ku/spring-data-neo4j that referenced this issue Jul 5, 2024
@michael-simons michael-simons self-assigned this Jul 10, 2024
@michael-simons
Copy link
Collaborator

Hej @ma-ku I'll investigate this week, but I am alone atm, will take a bit.

@michael-simons michael-simons added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 10, 2024
@michael-simons
Copy link
Collaborator

Oh well, there was little to triage, thanks for the excellent reproducer and fix. I attributed your contribution proper and this makes it into the pending release this weeks. Cheers.

michael-simons added a commit that referenced this issue Jul 10, 2024
…ionship.

This avoids having duplicate keys in the map projection used to collect the
nodes for each relationship in cases where a node has two relationships with the
same name to the same label in different directions.

Fixes #2918.

Co-authored-by: Mathias Kühn <[email protected]>
michael-simons added a commit that referenced this issue Jul 10, 2024
…ionship.

This avoids having duplicate keys in the map projection used to collect the
nodes for each relationship in cases where a node has two relationships with the
same name to the same label in different directions.

Fixes #2918.

Co-authored-by: Mathias Kühn <[email protected]>
michael-simons added a commit that referenced this issue Jul 10, 2024
…ionship.

This avoids having duplicate keys in the map projection used to collect the
nodes for each relationship in cases where a node has two relationships with the
same name to the same label in different directions.

Fixes #2918.

Co-authored-by: Mathias Kühn <[email protected]>
@ma-ku
Copy link
Contributor Author

ma-ku commented Jul 10, 2024

Thank you very much. Trying to help where I can ;-)

michael-simons added a commit that referenced this issue Jul 10, 2024
…ionship.

This avoids having duplicate keys in the map projection used to collect the
nodes for each relationship in cases where a node has two relationships with the
same name to the same label in different directions.

Fixes #2918.

Co-authored-by: Mathias Kühn <[email protected]>
michael-simons added a commit that referenced this issue Oct 24, 2024
…ut directional prefix.

This is a direct follow up on #2918, in which we added the suffix to the collection names. That change didn’t take custom queries into account and people are most likely still using the known pattern of `source_REL_target` and I would like to not break them.
Therefor, we check now in the values list if a collection without suffix exists if we didn’t find one with and if so, use that.

This fixes #2963.
michael-simons added a commit that referenced this issue Oct 24, 2024
…ut directional prefix.

This is a direct follow up on #2918, in which we added the suffix to the collection names. That change didn’t take custom queries into account and people are most likely still using the known pattern of `source_REL_target` and I would like to not break them.
Therefor, we check now in the values list if a collection without suffix exists if we didn’t find one with and if so, use that.

This fixes #2963.
michael-simons added a commit that referenced this issue Oct 24, 2024
…ut directional prefix.

This is a direct follow up on #2918, in which we added the suffix to the collection names. That change didn’t take custom queries into account and people are most likely still using the known pattern of `source_REL_target` and I would like to not break them.
Therefor, we check now in the values list if a collection without suffix exists if we didn’t find one with and if so, use that.

This fixes #2963.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants