Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Type error when retrieving a datetime value from database #486

Closed
knotseaborg opened this issue May 12, 2023 · 5 comments · Fixed by #488
Closed

Type error when retrieving a datetime value from database #486

knotseaborg opened this issue May 12, 2023 · 5 comments · Fixed by #488
Labels
bug Something isn't working

Comments

@knotseaborg
Copy link

The following error was found while retrieving a datetime value from the database
panic: expected value to have type dbtype.Time but found type time.Time

Neo4j Version: 5.7.0 Community
Neo4j Mode: Single instance
Driver version: Go driver v5.8.1
Go version: go1.20.4 linux/amd64
Operating System: Linux Mint 21.1 Vera 64-bit

Steps to reproduce

  1. Start Neo4j locally
  2. Create a node with datetime value
    create (n:Node{dateTimeLabel: datetime("2016-11-22T18:59:00.000+0900")});
  3. Attempting to retrieve node property triggers an error
result, err := neo4j.ExecuteQuery(ctx, driver, "MATCH (n:Node) RETURN n", map[string]any{}, neo4j.EagerResultTransformer)
if err != nil {
	panic(err)
}
node, _, err := neo4j.GetRecordValue[neo4j.Node](result.Records[0], "n")
if err != nil {
	panic(err)
}
dateTimeVal, err := neo4j.GetProperty[neo4j.Time](node, "dateTimeLabel")
if err != nil { //Non-nil error
	panic(err)
}

As an alternative, when neo4j.Time is replaced with time.Time, it does not match the type specification and an error is returned.

dateTimeVal, err := neo4j.GetProperty[time.Time](node, "dateTimeLabel")
if err != nil { //Non-nil error
	panic(err)
}

Expected behavior

Perhaps the node property dateTimeLabel should be of type dbtype.Time to avoid returning the error?

Actual behavior

Node property dateTimeLabel is of type time.Time

Stacktrace

For

dateTimeVal, err := neo4j.GetProperty[neo4j.Time](node, "dateTimeLabel")
if err != nil { //Non-nil error
	panic(err)
}
panic: expected value to have type dbtype.Time but found type time.Time

goroutine 1 [running]:
main.main()
	/home/---------
exit status 2

For

dateTimeVal, err := neo4j.GetProperty[time.Time](node, "dateTimeLabel")
if err != nil { //Non-nil error
	panic(err)
}
./neo4j.go:131:38: time.Time does not satisfy neo4j.PropertyValue (time.Time missing in bool | int64 | float64 | string | github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype.Point2D | github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype.Point3D | github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype.Date | github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype.LocalTime | github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype.LocalDateTime | github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype.Time | github.com/neo4j/neo4j-go-driver/v5/neo4j/dbtype.Duration | []byte | []any

Quick dirty fix

added time.Time to type PropertyValue interface in neo4j/graph.go

@fbiville fbiville added the bug Something isn't working label May 16, 2023
@fbiville
Copy link
Contributor

fbiville commented May 16, 2023

This is definitely a bug in the type constraint definition, thanks a lot for the report, a fix is on its way!

fbiville pushed a commit that referenced this issue May 16, 2023
Fixes #486

Signed-off-by: Florent Biville <florent.biville@neo4j.com>
@knotseaborg
Copy link
Author

No problem! Glad I could help.

@fbiville
Copy link
Contributor

The fix is going to be released towards the end of the month, with v5.9.0 FYI.

fbiville pushed a commit that referenced this issue May 17, 2023
Fixes #486

Signed-off-by: Florent Biville <florent.biville@neo4j.com>
@fbiville
Copy link
Contributor

@knotseaborg
Copy link
Author

Thanks for the update!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants