JsonApiDotNetCore icon indicating copy to clipboard operation
JsonApiDotNetCore copied to clipboard

Empty string ID is accepted in post resource request

Open bkoelman opened this issue 1 year ago • 1 comments

{
    Data = new PlayerDataInPostRequest
    {
        Id = null!, // FIXME: passing "" here works fine 🤔
    }
}

Originally posted by @verdie-g in https://github.com/json-api-dotnet/JsonApiDotNetCore/pull/1475#discussion_r1500200153


Interesting! I've debugged it down to RuntimeTypeConverter, which returns the target type's default value for an empty string. And there are tests for that behavior. However, I have no idea why it works like that. It was introduced in #139, all the way back in 2017.

When removing that behavior, all the tests are still green. However this is a very risky thing to change.

@maurei does this ring any bells? What's happening here is that a client sends "data": { "id": "", ... } in a post resource request, with the configuration that client-generated IDs are required.

Originally posted by @bkoelman in https://github.com/json-api-dotnet/JsonApiDotNetCore/pull/1475#discussion_r1500898488


Read into it a little bit. It sounds familiar for sure, but it doesn't really ring a concrete bell at this moment... 🤷

Originally posted by @maurei in https://github.com/json-api-dotnet/JsonApiDotNetCore/pull/1475#discussion_r1502161200

bkoelman avatar Feb 26 '24 21:02 bkoelman

I'm afraid this bug has become a "feature", ie people may be relying on the current behavior and we shouldn't break them in a minor or patch release.

bkoelman avatar Feb 26 '24 23:02 bkoelman