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

ODL Client 8.2.3 Breaks SaveChanges with BatchWithSingleChangeset #3150

Open
uffelauesen opened this issue Dec 16, 2024 · 1 comment · May be fixed by #3153
Open

ODL Client 8.2.3 Breaks SaveChanges with BatchWithSingleChangeset #3150

uffelauesen opened this issue Dec 16, 2024 · 1 comment · May be fixed by #3153
Assignees

Comments

@uffelauesen
Copy link
Contributor

uffelauesen commented Dec 16, 2024

Regression. ODL Client 8.2.3 fails to generate batch request.

Assemblies affected

OData .Net Client lib 8.2.3

Reproduce steps

Adding a new entity object to an existing tracked object's collection navigation properties and calling SaveChanges with BatchWithSingleChangeset now fails where as it used to (in ODL 8.2.2 and earlier) to correctly construct the $batch request with the one single change in it.

Despite the fact that the "reference" Trip/Pin service is buggy (and fails for the batch request on 8.2.2), you can use the following code to reproduce the issue...

            var q = from p in ctx.People.Take(1)
                          select p;

            var people = new DataServiceCollection<Person>(q);

            var aFriend = new Person();
            people.First().Friends.Add(aFriend);
            aFriend.UserName = Guid.NewGuid().ToString();
            aFriend.FirstName = "Test Friend";
            aFriend.LastName = "Test Friend";

            ctx.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset | SaveChangesOptions.PostOnlySetProperties);

Expected result

You get the $batch request generated and sent to the service like on ODL 8.2.2.

POST https://services.odata.org/TripPinRESTierService/(S(wb2pbbsx13f0npnrt4az5qwt))/$batch HTTP/1.1
Host: services.odata.org
OData-Version: 4.0
OData-MaxVersion: 4.0
Accept: multipart/mixed
Accept-Charset: UTF-8
User-Agent: Microsoft.OData.Client/8.2.2
Content-Type: multipart/mixed; boundary=batch_f0378b81-a652-420a-a1b4-34e4a523390a
Content-Length: 845

--batch_f0378b81-a652-420a-a1b4-34e4a523390a
Content-Type: multipart/mixed; boundary=changeset_6e82e35f-f898-42ed-8031-fc0bc575b6b6

--changeset_6e82e35f-f898-42ed-8031-fc0bc575b6b6
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 3

POST https://services.odata.org/TripPinRESTierService/(S(wb2pbbsx13f0npnrt4az5qwt))/People('angelhuffman')/Friends HTTP/1.1
OData-Version: 4.0
OData-MaxVersion: 4.0
Content-Type: application/json;odata.metadata=minimal
Accept: application/json;odata.metadata=minimal
Accept-Charset: UTF-8
User-Agent: Microsoft.OData.Client/8.2.2

{"@odata.type":"#Trippin.Person","FirstName":"Test Friend","LastName":"Test Friend","UserName":"b8afa014-5dc9-491f-847d-9d663be87e2a"}
--changeset_6e82e35f-f898-42ed-8031-fc0bc575b6b6--
--batch_f0378b81-a652-420a-a1b4-34e4a523390a--

Actual result

You get an exception on ODL 8.2.3:

Unhandled exception. Microsoft.OData.ODataException: The dependsOn Id: [1] in request [3] is not matching any of the request Id and atomic group Id seen so far. Forward reference is not allowed.
at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchWriter.ValidateDependsOnIds(String contentId, IEnumerable1 dependsOnIds) at Microsoft.OData.ODataBatchWriter.BuildOperationRequestMessage(Stream outputStream, String method, Uri uri, String contentId, String groupId, IEnumerable1 dependsOnIds)
at Microsoft.OData.MultipartMixed.ODataMultipartMixedBatchWriter.CreateOperationRequestMessageImplementation(String method, Uri uri, String contentId, BatchPayloadUriOption payloadUriOption, IEnumerable1 dependsOnIds) at Microsoft.OData.ODataBatchWriter.CreateOperationRequestMessageInternal(String method, Uri uri, String contentId, BatchPayloadUriOption payloadUriOption, IEnumerable1 dependsOnIds)
at Microsoft.OData.ODataBatchWriter.CreateOperationRequestMessage(String method, Uri uri, String contentId, BatchPayloadUriOption payloadUriOption, IEnumerable`1 dependsOnIds)
at Microsoft.OData.Client.ODataRequestMessageWrapper.CreateBatchPartRequestMessage(ODataBatchWriter batchWriter, BuildingRequestEventArgs requestMessageArgs, RequestInfo requestInfo, String contentId, Boolean isRelativeUri)
at Microsoft.OData.Client.BatchSaveResult.CreateRequestMessage(String method, Uri requestUri, HeaderCollection headers, HttpStack httpStack, Descriptor descriptor, String contentId)
at Microsoft.OData.Client.BaseSaveResult.CreateRequest(EntityDescriptor entityDescriptor)
at Microsoft.OData.Client.BatchSaveResult.GenerateBatchRequest()
at Microsoft.OData.Client.BatchSaveResult.BatchRequest()
at Microsoft.OData.Client.DataServiceContext.SaveChanges(SaveChangesOptions options)
at ReferenceService.Program.Main(String[] args) in C:\Users\Z6UFE\Source\Repos\ReferenceService\Program.cs:line 23

Additional detail

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

@corranrogue9
Copy link
Contributor

This may be related to @DButoyez recent change, we should investigate if that's the regression, and just investigate in general to address the issue.

uffelauesen added a commit to uffelauesen/odata.net that referenced this issue Dec 19, 2024
…xing when to add DependsOnIds. Add DependOnIds to missing code paths. Fixes OData#3150
@uffelauesen uffelauesen linked a pull request Dec 19, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants