odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

ODataException: To compute an entity's metadata, its key and concurrency-token property values must be provided

Open akshukla25 opened this issue 3 years ago • 15 comments

Entities having auto expand property is throwing an exception "ODataException: To compute an entity's metadata, its key and concurrency-token property values must be provided" when using $select=prop1.

Assemblies affected

Microsoft.OData.Core 7.7.3.0

Reproduce steps

This is an issue where entities have auto expand property enabled. So, even if we are requesting another property like displayName, it throws an exception below while writing the response using writeNestedResourceInfo(nestedResourceInfo).

GET ~/authorizationPolicy/authorizationPolicy?api-version=AGSbetaB-internal&$select=displayName

If id is also selected, we don't see this exception then. Example : GET ~/authorizationPolicy/authorizationPolicy?api-version=AGSbetaB-internal&$select=id, displayName

Expected result

Retrieve the displayName of the object requested.

Actual result

Microsoft.ODataException: "The entity instance value of type 'Microsoft.DirectoryServices.AuthorizationPolicy' doesn't have a value for property 'id'. To compute an entity's metadata, its key and concurrency-token property values must be provided."

akshukla25 avatar May 26 '21 19:05 akshukla25

I think autoexpand will end up being key to this issue. Because it's autoexpand, we will try and generate the nav link for which we need key values. I suspect this may be related to a recent change where we were silently swallowing exceptions when trying to determine key values.

mikepizzo avatar May 26 '21 19:05 mikepizzo

HI @akshukla25 It will be great if you can please share the stack trace for the exception

Sreejithpin avatar May 27 '21 16:05 Sreejithpin

@Sreejithpin, Stacktrace: [Microsoft.OData.ODataException: The entity instance value of type 'Microsoft.DirectoryServices.AuthorizationPolicy' doesn't have a value for property 'id'. To compute an entity's metadata, its key and concurrency-token property values must be provided.; at Microsoft.OData.Evaluation.ODataResourceMetadataContext.GetPrimitiveOrEnumPropertyValue(ODataResourceBase resource, String propertyName, String entityTypeName, Boolean isKeyProperty) at Microsoft.OData.Evaluation.ODataResourceMetadataContext.<>c__DisplayClass26_0.<GetKeyProperties>b__0(IEdmStructuralProperty p) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at Microsoft.OData.Evaluation.ODataResourceMetadataContext.GetKeyProperties(ODataResourceBase resource, ODataResourceSerializationInfo serializationInfo, IEdmEntityType actualEntityType) at Microsoft.OData.ODataWriterCore.AppendEntitySetKeySegment(ODataPath odataPath, Boolean throwIfFail) at Microsoft.OData.ODataWriterCore.EnterScope(WriterState newState, ODataItem item) at Microsoft.OData.ODataWriterCore.WriteStartNestedResourceInfoImplementation(ODataNestedResourceInfo nestedResourceInfo) at Microsoft.Online.GraphService.ODataHelperLibraryV4.RequestWriter.WriteNestedResource(ODataNestedResourceInfo nestedResourceInfo, IEnumerable1 resources, Action1 writeNestedResourceInfo, Action1 writeODataResourceSet, Action1 writeODataResource, Action writeEnd, String typeName, Boolean topLevelProperty) in X:\bt\1144038\repo\src\Dev\RestServices2\GraphService\ODataHelperLibraryV4\RequestWriter.cs at Microsoft.Online.GraphService.ODataHelperLibraryV4.RequestWriter.WriteNestedResource(ODataWriter odataWriter, ODataNestedResourceInfo nestedResourceInfo, IEnumerable`1 resources, String typeName) in X:\bt\1144038\repo\src\Dev\RestServices2\GraphService\ODataHelperLibraryV4\RequestWriter.cs

akshukla25 avatar May 27 '21 17:05 akshukla25

@akshukla25 Thanks , Also looks like you are using 7.7.3 version of the library. Can you please confirm

Sreejithpin avatar May 27 '21 18:05 Sreejithpin

Yes, mentioned assembly version in the description section.

akshukla25 avatar May 27 '21 18:05 akshukla25

@akshukla25 Thanks. Can you please share a repro with model and the request you are trying (if there is any other than given in the description)

Sreejithpin avatar May 27 '21 18:05 Sreejithpin

The request I am trying is GET ~/authorizationPolicy/authorizationPolicy?api-version=AGSbetaB-internal&$select=displayName, I can see this issue for RoleDefinitions as well: GET ~/roleDefinitions/?api-version=AGSbetaB-internal&$select=id,inheritsPermissionsFrom

akshukla25 avatar Jun 02 '21 01:06 akshukla25

@akshukla25 Thanks, Can you please share your model. Also will be great if you can please share a small repro as well which we can use to debug to get the issue

Sreejithpin avatar Jun 03 '21 16:06 Sreejithpin

roleDef.zip

akshukla25 avatar Jun 05 '21 00:06 akshukla25

This is a duplicate reported in https://github.com/OData/odata.net/issues/1149

vladascibulskis avatar Aug 12 '21 18:08 vladascibulskis

@Sreejithpin is there any update on this issue?

akshukla25 avatar Mar 07 '22 18:03 akshukla25

@mikepizzo, @Sreejithpin this issue is a blocker for us, could you please help?

akshukla25 avatar Mar 25 '22 22:03 akshukla25

Has anyone found a workaround?

spaasis avatar Sep 28 '22 05:09 spaasis

您好,我已收到您的邮件,并会尽快回复。This is an automatic reply, confirming that your e-mail was received.Thank you

ycymio avatar Sep 28 '22 05:09 ycymio

I have the same issue, any workaround?

FirewizzNL avatar Oct 11 '22 14:10 FirewizzNL

I have the same issue with an entity using auto-expand and it seems that the $select without the 'id' field results in this error. If 'id' field is added to the field list, then the results are returned correctly. I am using version 8.0.8. A workaround could be, I have implemented for some other scenarios, is to override the 'OnActionExecuting' method in custom implementation of EnableQueryAttribute. In the method, you can check if the call is being made to the entity in question and if there is a $select query option specified. If yes, then update the $select query option in the query string and add 'id' field to the list.

vibatra avatar Nov 07 '22 20:11 vibatra

您好,我已收到您的邮件,并会尽快回复。This is an automatic reply, confirming that your e-mail was received.Thank you

ycymio avatar Nov 07 '22 20:11 ycymio