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: error unmarshalling to time.time #181

Open
2 tasks done
MaxThom opened this issue Nov 8, 2024 · 2 comments
Open
2 tasks done

Bug: error unmarshalling to time.time #181

MaxThom opened this issue Nov 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@MaxThom
Copy link

MaxThom commented Nov 8, 2024

Describe the bug

SurrealDb: v1.5.4
SDK: v0.3.0

While upgrading to the new version of the sdk, I keep getting this error when umarshalling my Device struct
error listing devices from database: cbor: cannot unmarshal array into Go struct field connection.RPCResponse[[]github.com/surrealdb/surrealdb%2ego.QueryResult[[]github.com/maxthom/mir/pkgs/mir_models.Device]].result of type time.Time

I have two time.Time field in those structs:

Device struct {
	ApiVersion string     `json:"apiVersion" yaml:"apiVersion"`
	ApiName    string     `json:"apiName" yaml:"apiName"`
	Status     Status     `json:"status" yaml:"status"`
}

type Status struct {
	Online         bool      `json:"online" yaml:"online"`
	LastHearthbeat time.Time `json:"lastHearthbeat" yaml:"lastHearthbeat"`
	Schema         Schema    `json:"schema" yaml:"schema"`
}

type Schema struct {
	CompressedSchema []byte    `json:"compressedSchema" yaml:"compressedSchema"`
	PackageNames     []string  `json:"packageNames" yaml:"packageNames"`
	LastSchemaFetch  time.Time `json:"lastSchemaFetch" yaml:"lastSchemaFetch"`
}

Something I have notice, before, when creating the DeviceObject using Create, the timestamps where set to the zero value of time, and with the new sdk, they are set to NULL. It works unmarshalling when null, but not when set or zero value
Before:

status: {
		lastHearthbeat: d'0001-01-01T00:00:00Z',
		online: false,
		schema: {
			compressedSchema: NULL,
			lastSchemaFetch: d'0001-01-01T00:00:00Z',
			packageNames: NULL
		}
	}

After:

status: {
		lastHearthbeat: NULL,
		online: false,
		schema: {
			compressedSchema: NULL,
			lastSchemaFetch: NULL,
			packageNames: NULL
		}
	}

I'm not exactly sure thats the issue.
Do i need to upgrade to v2.0 of surreal?
Do i need to use models.CustomDateTime instead of time.Time?

Steps to reproduce

  1. Create a document with go time.Time set to a value
  2. Retrieve and unmarshal the document

Expected behaviour

Unmarshal properly

SurrealDB version

1.5.4

Contact Details

[email protected]

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
@MaxThom MaxThom added the bug Something isn't working label Nov 8, 2024
@MaxThom
Copy link
Author

MaxThom commented Nov 8, 2024

I tried replacing my time.Time with models.CustomDateTime. Unmarshalling works, but the value look truncated.
This get written
2024-11-08 20:12:54.317842571 +0000 UTC
and this get read
1970-01-01 00:00:00.317842571 +0000 UTC
just the ns are there...
this is in the db
d'1970-01-01T00:00:00.354Z'

@MaxThom
Copy link
Author

MaxThom commented Nov 8, 2024

Moreover, except the create, I am using I am using the Query function. This is my hearbeat update query
UPDATE devices MERGE {status: {lastHearthbeat: $BEAT,online: $ON,},} WHERE spec.deviceId = "0xf86tlm";
Where BEAT is a time.Time

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

1 participant