OData / OData/AspNetCoreOData

Related entities are not de-serialized correctly when both: deep insert entities and bind operations are present in the request

Open
#784 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected
Microsoft.AspNetCore.OData, Version=8.0.12.0

Describe the bug.
When inserting a new entity with a POST request, related entities MAY be specified using the same representation as for an expanded navigation property or a bind operation: http://docs.oasis-open.org/odata/odata-json-format/v4.0/cs01/odata-json-format-v4.0-cs01.html#_Toc365464707. However, if both are present in the request's body, ODataEdmTypeDeserializer only de-serializes related resources represented by bind operations and ignores expanded entities.

Reproduce steps
Consider the following HTTP POST request payload:

{
   "@odata.type": "#Com.Ingr.SampleApi.V1.Pipeline",
   "Name": "390207-MC4",
   "Description": null,
   "Pipes@odata.bind": [
      "Pipes('443C7C34-A96C-4499-950F-BDCF06630783')"
   ],
  "Pipes": [
   {
     "@odata.type":"#Com.Ingr.SampleApi.V1.Pipe",
     "Name":"Y0001", 
     "Description":null,
     "IsInsulated":false
    }
  ]
}

In this example, the new pipeline entity is created with 2 related pipes: the first pipe already exists and is represented by the bind operation and the second pipe should be created using deep insert operation. However, after the pipeline entity is de-serialized, its Pipes navigation property contains only one related pipe instance represented by the bind operation with just id populated. The second pipe is not present in the Pipes collection.

Data Model
Because our EDM model is dynamic we use untyped data model represented by EdmEntityObject / EdmComplexObject objects. CLR types are not used.

EDM (CSDL) Model

Request/Response

Expected behavior
I would expect the Pipes navigation property to contain expanded Pipe entity after de-serialization.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Please share your call stack or any error message
Add any other context about the problem here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ODataEdmTypeDeserializer and the handling of navigation properties represented by both @odata.bind and expanded entities. Reproduce the payload using the untyped EdmEntityObject and EdmComplexObject model described in the issue, then verify that the Pipes collection retains both the bound entity and the expanded entity after deserialization.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.