I’m just getting started with Dgraph, but I’m hitting some behavior I don’t understand.
The gist of it is that if you create a predicate of type datetime and try to store the date 0001-01-01T00:00:00Z, the value will store as an empty string "". That value doesn’t seem to be a validate datetime, so it seems like it should (1) error if that value for a date isn’t acceptable, (2) treat it as though the predicate were omitted entirely, or (3) store it as is. Is there a reason or documentation for the current behavior?
I ran into this when doing my first interaction with Dgraph using the Go client. I queried for a node, made an update to an unrelated predicate, and then mutated it. when running the program a second time, part the submits the query and then unmarshals it back into my struct resulted in a json error which wasn’t there the first time the node was fetched: parsing time """" as ""2006-01-02T15:04:05Z07:00"": cannot parse """ as "2006". The problem was that the result now contained an empty string for a date value instead of omitting the field completely, as was the case the first time though before my mutate saved an empty string.
For this specific use case I could work around this by using pointers to time.Time values, which may be the right approach anyway. But I’d still like to figure out exactly what’s going on here.
@arijit
Digging into this issue, I found that it is working as intended. The Time package considers
“0001-01-01T00:00:00Z” as a zero time, from which seconds are counted. In this particular line in dgraph we are checking if the value is zero time, then we return an empty string.
Now after this PR, when we are not accepting empty datetime in mutation, I think it would be right to return “0001-01-01T00:00:00Z” (a zero time) instead of an empty string.
Yeah, we should be returning the zero time(“0001-01-01T00:00:00Z”) instead of an empty string if the user stored that in the DB. Also look into the linked issue while you fix this to avoid introducing a regression.