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] "infinity" date fails to deserialize #41

Closed
kamyker opened this issue May 23, 2022 · 3 comments
Closed

[Bug] "infinity" date fails to deserialize #41

kamyker opened this issue May 23, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@kamyker
Copy link

kamyker commented May 23, 2022

Inifinity is insterted when using npgsql https://www.npgsql.org/doc/types/datetime.html , then postgrest fails to desterilize it

System.FormatException : String '-infinity' was not recognized as a valid DateTime.
   at Postgrest.Converters.DateTimeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Postgrest.Responses.ModeledResponse`1..ctor(BaseResponse baseResponse, JsonSerializerSettings serializerSettings, Boolean shouldParse)
   at Postgrest.Helpers.MakeRequest[T](HttpMethod method, String url, JsonSerializerSettings serializerSettings, Object data, Dictionary`2 headers)
@steve-chavez
Copy link

steve-chavez commented May 24, 2022

PostgREST is able to use -/+Infinity with no problem:

curl localhost:3000/articleStars?createdAt=gte.+Infinity
[]


curl localhost:3000/articleStars?createdAt=gte.-Infinity
[{"articleId":1,"userId":1,"createdAt":"2015-12-08T04:22:57.472738"},
 {"articleId":1,"userId":2,"createdAt":"2015-12-08T04:22:57.472738"},
 {"articleId":2,"userId":3,"createdAt":"2015-12-08T04:22:57.472738"},
 {"articleId":3,"userId":2,"createdAt":"2015-12-08T04:22:57.472738"},
 {"articleId":1,"userId":3,"createdAt":"2015-12-08T04:22:57.472738"}]

(More special values documented in: https://postgrest.org/en/latest/how-tos/working-with-postgresql-data-types.html)

So I guess this must be an issue with postgrest-csharp itself.

@acupofjose
Copy link
Contributor

acupofjose commented May 24, 2022

@steve-chavez thanks for the reply! Wasn't aware of being able to use -/+Infinity like that - good to know!

@kamyker to clarify, you have a record in the database with Datetime as its type and a value of -infinity and you are attempting to deserialize into a C# model that has DateTime as its type as well?

Since we have to return a DateTime, would it be alright if those were coerced into DateTime.MinValue and DateTime.MaxValue for -/+Infinity respectively?

@acupofjose acupofjose added the bug Something isn't working label May 24, 2022
@kamyker
Copy link
Author

kamyker commented May 24, 2022

@steve-chavez thanks for the reply! Wasn't aware of being able to use -/+Infinity like that - good to know!

@kamyker to clarify, you have a record in the database with Datetime as its type and a value of -infinity and you are attempting to deserialize into a C# model that has DateTime as its type as well?

Yes, exactly.

Since we have to return a DateTime, would it be alright if those were coerced into DateTime.MinValue and DateTime.MaxValue for -/+Infinity respectively?

Yes the same way as npgsql does.

acupofjose added a commit that referenced this issue May 24, 2022
- `DateTimeConverter` supports reading values of `infinity` and `-infinity`, coerced into `DateTime.MaxValue` and `DateTime.MinValue` respectively
- Update Contract resolver to support `DateTime`, DateTime?`, `List<DateTime>`, and `List<DateTime>`
- Update Tests for new functionality
acupofjose added a commit that referenced this issue May 25, 2022
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