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

Fixed invalid match when trying to attach to a node whose id is 0 #360

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrbig
Copy link
Contributor

@mrbig mrbig commented Apr 1, 2022

When trying to attach a node where the id is 0 the generated CypherQuery was missing the end node from the MATCH part.

This bug come out when neo started to reuse ids of deleted nodes: because the first id is 0, when this happened instead of connecting to the new node, a ton of edges were created between nodes with the same label.

This patch checks if the end node has an id, and won't ignore it from the query even if the value is the numeric 0.

For missing values (false, null, unset) the behavior was not changed.

I have also added a unit test to visualize the problem.


if ($attributes['end']['id']['value']) {
if ($attributes['end']['id']['value'] || $attributes['end']['id']['value'] === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

thanks for this fix, it's a gotcha! I don't know how we've gone so long without facing such issue 😅

Do you think we could do if (isset($attributes['end']['id']['value']) instead of the two checks? Haven't had the chance to try it yet sorry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, if you have a running database it's unlikely to delete the very first node after a while. :)

I couldn't find the usecase when this is called without a value attribute, but I didn't want to break it anyhow. It's not absolutely clear how it is used, because this is already in an if (isset($attributes['end'])) check (line 870).

Also the current released check is also not completely notice free, because a $attribute['end']['id'] without a value key would throw an undefined index notice on the check.

So my best bet is, that it is unlikely that this method gets called in the way it is checked.

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