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

unixtime format time.Time is always omitempty #178

Open
lparkes opened this issue Oct 3, 2021 · 2 comments
Open

unixtime format time.Time is always omitempty #178

lparkes opened this issue Oct 3, 2021 · 2 comments

Comments

@lparkes
Copy link

lparkes commented Oct 3, 2021

I have noticed that when storing time.Time values with the unixtime option, that zero value are always omitted. With the following struct, the MyFIeld is never stored if its value is 0.

type MyStruct struct {
	MyField     time.Time `dynamo:",unixtime,allowempty"`
}

The top level README is also slightly misleading. It talks about the TextMarshaller defaulting to omitempty and time.Time triggering this behaviour, but it doesn't mention that when using the unixtime enconding, the TextMarshaller is ignored and there is special code in the library to always omitempty.

Without this field present my objects don't appear in my global secondary index which does make it a touch difficult for me to query them. There may be smarter things I can do with AWS, but I'd prefer to just store 0 in that field.

@guregu
Copy link
Owner

guregu commented Oct 3, 2021

Sounds like a bug, thanks. We need to document that behavior and fix allowempty for it. Shouldn't be too hard to fix it. I'll take a look.

I believe the unixtime feature was originally an outside contribution intended for TTL expiration in which 0 values are meaningless. However, I agree the current behavior is confusing.

I'll also tag #113 because I want to go over all the automatic behavior for v2 and have it make more sense. This probably shouldn't be automatically omitted at all in a future version.

@lparkes
Copy link
Author

lparkes commented Oct 3, 2021

I wrote a fix for this, but it turned out to be less useful than I thought (for me anyway).

I also had the bright idea of switching my code to use time.Unix(0, 0) as my zero value. Since it's not a time.Time zero value it gets stored just fine and I'm only creating these zero values in one place so it was an easy change.

I'm pretty sure I don't need to use the unixtime but I've seen date parsing in general consume a startling amount of CPU in the past.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants