OData / OData/WebApi

Conflict on TypedEdmStructuredObject when working with multiple models (for API versioning)

Open
#960 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P4
Dominant language
C#
Stars
864
Forks
467
PR merge metrics
No merged PRs in 30d

Description

System.Web.OData.Formatter.Serialization.TypedEdmStructuredObject has a static cache of "get_" accessors for fast retrieval of properties values. The problem is that the key of the model is a tuple of {PropertyName, CLRType} and this being static is causes overwrites when working with multiple models on the same type in a single process.

Assemblies affected

System.Web.OData.dll

Reproduce steps
  1. Create a simple class type "MyEntity" with properties PropertyNew and PropertyOld
  2. Have one EDM model, let's say for API 1.0 that maps "Property" to "MyEntity.PropertyOld" and another EDM Model that maps "Property" to "MyEntity.PropertyNew"
  3. Perform a get on those 2 API versions routing through the different models.
Expected result

When the request is routed through model "1.0" the value of "Property" should come from PropertyOld and when the request is routed through model "1.1" the value of "Property" should come from PropertyNew.

Actual result

Although the request is routed through the correct models and the serializer and having the correct model reference, the value of the entity "Property" always come to whichever CLR property it was first accessed, despite the model saying otherwise.

Additional details

Root cause is the static cache on System.Web.OData.Formatter.Serialization.TypedEdmStructuredObject which doesn't key it's cache from the model instance, but only property name and CLR type.

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

Locate System.Web.OData.Formatter.Serialization.TypedEdmStructuredObject in System.Web.OData.dll and inspect its static accessor cache. Reproduce the issue with two EDM models mapping the same property name to different CLR properties, then verify that each API version returns the value selected by its own model.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.