Zaid-Ajaj / Fable.Remoting

Type-safe communication layer (RPC-style) for F# featuring Fable and .NET Apps
https://zaid-ajaj.github.io/Fable.Remoting/
MIT License
274 stars 57 forks source link

Possible issue with date strings and result type #354

Closed Darkle closed 12 months ago

Darkle commented 12 months ago

Hi, I seem to be encountering an issue with the fable remoting dotnet client deserialization of strings when the string looks like an ISO date string.

With the following types:

module SharedTypes

type PostTimestamp = string

type Api =
    { getPostTimestamp: unit -> Async<PostTimestamp>
      getPostTimestamp_Result: unit -> Async<Result<PostTimestamp, exn>> }

and the following server code:

open System
open Microsoft.AspNetCore.Builder
open Fable.Remoting.Server
open Fable.Remoting.AspNetCore
open Microsoft.AspNetCore.Hosting
open SharedTypes

let postTimestamp = "2023-12-03T11:49:41"

let getPostTimestamp () = async { return postTimestamp }
let getPostTimestamp_Result () = async { return Ok(postTimestamp) }

let apiPostsEndpoints: Api =
    { getPostTimestamp = getPostTimestamp
      getPostTimestamp_Result = getPostTimestamp_Result }

let webApp = Remoting.createApi () |> Remoting.fromValue apiPostsEndpoints

let configureApp (app: IApplicationBuilder) = app.UseRemoting(webApp)

[<EntryPoint>]
let main _ =
    WebHostBuilder()
        .UseKestrel()
        .Configure(Action<IApplicationBuilder> configureApp)
        .UseUrls("http://localhost:8088")
        .Build()
        .Run()

    0

and the following client code:

module clientThing

open Fable.Remoting.DotnetClient
open SharedTypes

let server = Remoting.createApi "http://localhost:8088" |> Remoting.buildProxy<Api>

[<EntryPoint>]
let main _ =
    async {
        let! res = server.getPostTimestamp ()

        printfn "getPostTimestamp: %A" res

        let! res = server.getPostTimestamp_Result ()

        match res with
        | Ok r -> printfn "getPostTimestamp_Result: %A" r
        | Error e -> printfn "error: %A" e

    }
    |> Async.RunSynchronously

    0

I get the following output:

getPostTimestamp: "2023-12-03T11:49:41"
getPostTimestamp_Result: "12/03/2023 11:49:41"

You can see that the api route that returns the post inside of a Result alters the string. It seems like it infers that it is an ISO date string and parses it as a date, then converts it back to a string.

Repo here: https://github.com/Darkle/fable-remoting-issue

Details:

I searched through previous issues, perhaps this is related: https://github.com/Zaid-Ajaj/Fable.Remoting/issues/304

Zaid-Ajaj commented 12 months ago

Hi there @Darkle I believe this might an issue with how the serializer on the dotnet client is setup, it should not infer anything from strings, something like DateTimeHandling.None on the serializer options. I need to check that

Zaid-Ajaj commented 12 months ago

Fixed as of Fable.Remoting.DotnetClient v3.32 :rocket: it was indeed the date parse handling that needed to be disabled. Thanks a lot for filing the issue and for the detailed report. Please take the new package for a spin and see if it fixes the issue. I expect that it is resolved but feel free to re-open if the problem persists

Darkle commented 12 months ago

Wow, thanks so much for the quick response! I just tried the updated version and it indeed does fix the issue.

Cheers.