-
Notifications
You must be signed in to change notification settings - Fork 68
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
Bug: UnmarshalRaw panics when unmarshalling object #139
Comments
I've just quickly went through the code of the current commit and it seems the RawQuery type still expects array type RawQuery[I any] struct {
Status string `json:"status"`
Time string `json:"time"`
Result []I `json:"result"`
Detail string `json:"detail"`
} this is the code I ran with the current commit of package main
import (
"fmt"
"github.com/surrealdb/surrealdb.go"
"github.com/surrealdb/surrealdb.go/pkg/conn/gorilla"
"github.com/surrealdb/surrealdb.go/pkg/marshal"
)
type Id struct {
Id int `json:"id"`
}
func main() {
ws := gorilla.Create()
conn, err := ws.Connect("ws://localhost:8000/rpc")
if err != nil {
fmt.Print(err.Error())
return
}
db, err := surrealdb.New("ws://localhost:8000/rpc", conn)
if err != nil {
fmt.Print(err.Error())
return
}
defer db.Close()
if _, err = db.Signin(&surrealdb.Auth{
Namespace: "namespace",
Database: "database",
Username: "root",
Password: "root",
}); err != nil {
fmt.Print(err.Error())
return
}
iddb, err := db.Query(`RETURN {
id: 3
}`, nil)
if err != nil {
fmt.Print(err.Error())
return
}
var id []marshal.RawQuery[Id]
err = marshal.UnmarshalRaw(iddb, &id)
if err != nil {
fmt.Print(err.Error())
}
fmt.Print(id)
} it returns error but no longer panics
it got fixed for me when I changed the type of result to It also wokrs as expected when the query returns array. The type parameter just needs to alos be array iddb, err := db.Query(`RETURN [{
id: 3
}]`, nil)
var id []marshal.RawQuery[[]Id]
err = marshal.UnmarshalRaw(iddb, &id) I can open PR with the fix |
Feel free to Open PR, all contributions are welcome. |
its one line change in SmartUnmarshall |
Describe the bug
When .Query() returns object UnmarshalRaw panics with
Steps to reproduce
Expected behaviour
UnmarashalRaw should correctly unmarshall the response
There is workaround by doing
SurrealDB version
1.5.0 for linux on x86_64
Contact Details
No response
Is there an existing issue for this?
Code of Conduct
The text was updated successfully, but these errors were encountered: