Open gokussx4 opened 1 year ago
Thanks for informing will check and update you .
@gokussx4 Thanks for the detailed report. Some clarifying questions:
The error check that is happening is ensuring that the payload has id
for the save operation, which is required by the Service.
Removing the check would make the operation fail anyway but fail after making a network request with an HTTP 400 status code. Which means that even if we remove it, the operation will still fail, not succeed. Simply put, no write operation on a document can be done if the payload has no id
(the extension is just catching it instead of failing on a network).
Looking at your expected behavior:
The document retrieved and changed with the single item value binder should be able to be read and changed without error.
This is impossible. Even if the check is removed, if you attempt to persist the change without having an id
when the model is serialized, it will be rejected by the service.
When using the CosmosDB single item value binder with Azure Functions, this error will occur even if the document read in is a lowercase 'id' property and the ICosmosDBSerializerFactory implementation is injected per the dev blog here.
Adding a document with the IAsyncCollector works as expected without need of workarounds defined.
I think that removing the restriction of a lower case id field in the encapsulated usage of newtonsoft within the binder code would resolve the issue. As long as the id field is found (case insensitive) after the JObject is formed (from the JObject.FromObject call) then the extension should not care due to the fact that the serializer defined by the ICosmosDBSerializerFactory is responsible for the serialization settings. The underlying CosmosSDK, which the extension is dependent on, would throw an error if the id field is not lowercase. https://github.com/Azure/azure-webjobs-sdk-extensions/blob/0af7d172090d1b698b13ebcaef628177a8c3605f/src/WebJobs.Extensions.CosmosDB/Bindings/CosmosDBItemValueBinder.cs#L120
Repro steps
Provide the steps required to reproduce the problem
Expected behavior
The document retrieved and changed with the single item value binder should be able to be read and changed without error.
Actual behavior
The document is found and deserialized but is unable to write the change because a lowercase 'id' field could not be found.
Known workarounds
Apply JsonProperty (newtonstoft) attribute forcing a lowercase 'id' field or set JsonConvert.DefaultSettings static property to camel case settings.
Related information
Provide any related information
Example code Program.cs
CosmosDBSerializationFactory
Function