Bug attempting to Match after a Consume inside a transaction.
happilymarrieddad opened this issue · 2 comments
happilymarrieddad commented
Bug report
When consuming data inside a transaction and then trying to create later it causes a strange state being invalid error. Note, this does not happen in the 4.2.2 version of the driver. Thanks!
Expected success, but got an error:
<*errors.errorString | 0xc00024c810>: {
s: "Invalid state 4, expected: [3]",
}
Invalid state 4, expected: [3]
Neo4j Version: 4.2.3 (enterprise)
Neo4j Mode: Single instance
Driver version: Go driver v4.2.3
Operating System: OSX Sierra
Steps to reproduce
- Start Neo4j on a AWS instance
- Run the following Go code in a test
Expected behavior
The third query should just create the node
Actual behavior
The above error happens
Here is the Go test code
package tests_test
import (
"fmt"
"testing"
neo4j "github.com/neo4j/neo4j-go-driver/v4/neo4j"
)
var (
clearGraph = func(sesh neo4j.Session) (err error) {
_, err = sesh.Run(
fmt.Sprintf(`
OPTIONAL MATCH (m:%s)
WITH COLLECT(m) AS migrations
MATCH (n) WHERE NOT (n in migrations)
DETACH DELETE n
`, "`__Neo4jMigration`"), //sprintf so we can back-tick the migration node name
nil,
)
return
}
)
func TestTestingTransactionConsume(t *testing.T) {
auth := neo4j.NoAuth()
driver, err := neo4j.NewDriver("bolt://localhost:7687", auth)
if err != nil {
panic(err)
}
sesh := driver.NewSession(neo4j.SessionConfig{
AccessMode: neo4j.AccessModeWrite,
})
defer sesh.Close()
clearGraph(sesh)
mp := make(map[string]interface{})
tx, err := sesh.BeginTransaction()
if err != nil {
fmt.Print("1 Err: " + err.Error())
t.Fail()
}
_, err = tx.Run(`
CREATE (c:Cookie{name: '1'})
`, mp)
if err != nil {
fmt.Print("2 Err: " + err.Error())
t.Fail()
}
res, err := tx.Run(`
CREATE (cj:CookieJar{name: '2'}) WITH cj
MATCH (c:Cookie{name: '1'})
CREATE (c)-[:MEMBER]->(cj)
`, mp)
if err != nil {
fmt.Print("3 Err: " + err.Error())
t.Fail()
}
_, err = res.Consume()
if err != nil {
fmt.Print("4 Err: " + err.Error())
t.Fail()
}
_, err = tx.Run(`
MATCH (c:Cookie{name: '1'})
SET c.type = 'Choc Chip'
`, mp)
if err != nil {
fmt.Print("5 Err: " + err.Error())
t.Fail()
}
err = tx.Commit()
if err != nil {
fmt.Print("6 Err: " + err.Error())
t.Fail()
}
}
2hdddg commented
I'll have a look at it on Monday but are you sure that you get the error from the third Run? From the state expectations it looks like it should be an error returned from the commit.
2hdddg commented
Should be fixed with#197