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

Bug: cbor: cannot unmarshal array into Go struct field #169

Closed
2 tasks done
agufagit opened this issue Oct 29, 2024 · 3 comments
Closed
2 tasks done

Bug: cbor: cannot unmarshal array into Go struct field #169

agufagit opened this issue Oct 29, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@agufagit
Copy link

agufagit commented Oct 29, 2024

Describe the bug

for Query function, got error

cbor: cannot unmarshal array into Go struct field 
connection.RPCResponse[github.com/surrealdb/surrealdb%2ego.QueryResult[ReturnUser]].result of type 
surrealdb.QueryResult[ReturnUser·1] (cannot decode CBOR array to struct without toarray option)

Steps to reproduce

response cbor data structure:

{"id": "XTzysggrWya1sScd", "result": [{"result": {"id": 8(["user", "zg9z3vhr0cbvm6lsfzs7"]), "storage_id": "buc93y5caz06xsft1zin"},
"status": "OK", "time": "19.579786ms"}]}
type ReturnUser struct {
  ID        string `json:"id"`
  StorageID string `json:"storage_id"`
}

Expected behaviour

no error

SurrealDB version

surreal 2.0.4

Contact Details

No response

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@agufagit agufagit added the bug Something isn't working label Oct 29, 2024
@TheRangiCrew
Copy link
Contributor

Your ID field in the struct needs to be type models.RecordID. That is how the CBOR Unmarshal knows it is a record ID. Later on your then get the value of the table or ID by doing recordID.ID or something along those lines.
Also if your query is expected to return multiple records, the query needs to provide the type as a slice (i.e. Query[[]user](...).

@agufagit
Copy link
Author

I was under the impression that string type will be automatically parsed to string based on discussion here #160

@remade remade self-assigned this Oct 31, 2024
@agufagit
Copy link
Author

@remade no need to work on this, I worked on this for 2 days, there is no way to make this happen, the closest way is to define a new type type RecordIDBasic string, which still needs to be casted to string type. I decided I'll just use RecordId struct. and make changes to my code.

The only way to make this happen is on cbor side, which I left a discussion fxamacker/cbor#599

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

No branches or pull requests

3 participants