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

Open
vga91 opened this issue Mar 15, 2024 · 2 comments
Open

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

vga91 opened this issue Mar 15, 2024 · 2 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Blocked
Development

No branches or pull requests

1 participant