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 #13435

Open
vga91 opened this issue Mar 28, 2024 · 0 comments
Open

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

vga91 opened this issue Mar 28, 2024 · 0 comments

Comments

@vga91
Copy link

vga91 commented Mar 28, 2024

From version 5.18.0, the apoc.cypher.runSchemaFile does not seem to work as correctly as before, if an EquivalentSchemaRuleAlreadyExistsException is thrown.

I created an issue in the APOC repo.

But it's probably a kernel problem,
as I have isolated the problem, and created a simple test case, as follows:

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 {
            // it throws an EquivalentSchemaRuleAlreadyExistsException and remains in pending
            db.executeTransactionally("CALL my.proc()", Map.of(), Result::resultAsString);
        } catch (Exception e) {
            Assert.assertTrue(e.getMessage().contains("equivalent constraint already exists"));
        }
    }
}

Additional notes

  • The issue also occurs with a test container and with a real Neo4j instance.
  • Up to 5.17.0 the test case works correctly
  • 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"));
        }
    }

Expected behavior

The procedure correctly ends the execution

Actual behavior

The procedure remains in pending


  • Neo4j version: 5.18.0
  • Operating system: Mac OS Ventura
  • API/Driver: Java API/Cypher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants