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

The apoc.cypher.runSchemaFile() never finishes execution #4015

Closed
vga91 opened this issue Mar 15, 2024 · 4 comments
Closed

The apoc.cypher.runSchemaFile() never finishes execution #4015

vga91 opened this issue Mar 15, 2024 · 4 comments

Comments

@vga91
Copy link
Collaborator

vga91 commented Mar 15, 2024

Expected Behavior (Mandatory)

The procedure should finish correctly.

Actual Behavior (Mandatory)

The procedure never finishes execution.

How to Reproduce the Problem

Starting from version 5.18.0, the apoc.cypher.runSchemaFile() has the following bug.

Steps (Mandatory)

  • Create a constraint: CREATE CONSTRAINT uniqueConstraint FOR (n:Person) REQUIRE n.name IS UNIQUE
  • Create a file.cypher with the same constraint statement, so as to produce an EquivalentSchemaRuleAlreadyExistsException:
CREATE CONSTRAINT uniqueConstraint FOR (n:Person) REQUIRE n.name IS UNIQUE
  • Executes the query: CALL apoc.cypher.runSchemaFile('file.cypher')
  • The procedure never stops
  • NB: If we stops the execution and retry the APOC, the procedure works

Versions

  • OS: OSX
  • Neo4j: 5.18.0
  • Neo4j-Apoc: 5.18.0
@vga91
Copy link
Collaborator Author

vga91 commented Mar 15, 2024

Isolated test case

Note that the issue occurs also with a test container and with a real Neo4j instance

import apoc.util.TestUtil;
import org.junit.*;
import org.neo4j.graphdb.*;
import org.neo4j.procedure.*;
import org.neo4j.test.rule.*;

import java.util.Map;
import java.util.stream.Stream;

public class PendingTest {

    public static class MockProcedure {
        public record MockResult(String value) {}

        @Context public GraphDatabaseService db;

        @Procedure(name = "my.proc", mode = Mode.SCHEMA)
        public Stream<MockResult> myProcedure() {
            // should throw an EquivalentSchemaRuleAlreadyExistsException,
            // instead it remains in pending
            db.executeTransactionally("CREATE CONSTRAINT FOR (n:Person) REQUIRE n.name IS UNIQUE", Map.of(), Result::resultAsString);
            return Stream.of(new MockResult("test"));
        }
    }

    @ClassRule
    public static DbmsRule db = new ImpermanentDbmsRule();

    @BeforeClass
    public static void setUp() {
        TestUtil.registerProcedure(db, MockProcedure.class);
    }

    @Test
    public void test() {
        db.executeTransactionally("CREATE CONSTRAINT FOR (n:Person) REQUIRE n.name IS UNIQUE");

        try {
            db.executeTransactionally("CALL my.proc()", Map.of(), Result::resultAsString);
        } catch (Exception e) {
            Assert.assertTrue(e.getMessage().contains("equivalent constraint already exists"));
        }
    }
}

NOTE: By changing the MockProcedure class to the following, solves the problem:

    public static class MockProcedure {
        public record MockResult(String value) {}

        @Context public Transaction tx;

        @Procedure(name = "my.proc", mode = Mode.SCHEMA)
        public Stream<MockResult> myProcedure() {
            tx.execute("CREATE CONSTRAINT FOR (n:Person) REQUIRE n.name IS UNIQUE", Map.of()).resultAsString();
            return Stream.of(new MockResult("test"));
        }
    }

@vga91
Copy link
Collaborator Author

vga91 commented Mar 28, 2024

Since it might be a Neo4j issue, I also created a similar issue in the main repository

\cc @jexp

@vga91
Copy link
Collaborator Author

vga91 commented Nov 26, 2024

Update from trello card (id Y5ASTClI):

Could be https://github.com/neo4j/apoc/pull/578.
When merging that PR I was unaware of the dependency between core and extended.
There were some unused (in core) code paths that I removed, might be that they were called from extended.
Sorry about this in that case!


Check if the bug is still present

@vga91
Copy link
Collaborator Author

vga91 commented Nov 27, 2024

Currently, using apoc/neo4j 5.25 the problem is no longer present, by executing a

CALL apoc.cypher.runSchemaFile('file.cypher')

the procedure returns an empty result.

While executing

CALL apoc.cypher.runSchemaFile('file.cypher', {reportError: true})

the following error like this one is thrown:

{
  "error": "Constraint already exists: Constraint( id=4, name='constraint_a831e4ce', type='UNIQUENESS', schema=(:Person {name}), ownedIndex=3 )"
}

@vga91 vga91 closed this as completed Nov 27, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done (to cherry-pick) in APOC Extended Larus Nov 27, 2024
@vga91 vga91 moved this from Done (to cherry-pick) to Done in APOC Extended Larus Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant