odata.net
odata.net copied to clipboard
ODataException: To compute an entity's metadata, its key and concurrency-token property values must be provided
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."
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.
HI @akshukla25 It will be great if you can please share the stack trace for the exception
@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.Buffer
1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable
1 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, Action
1 writeNestedResourceInfo, Action1 writeODataResourceSet, Action
1 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 Thanks , Also looks like you are using 7.7.3 version of the library. Can you please confirm
Yes, mentioned assembly version in the description section.
@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)
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/
@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
This is a duplicate reported in https://github.com/OData/odata.net/issues/1149
@Sreejithpin is there any update on this issue?
@mikepizzo, @Sreejithpin this issue is a blocker for us, could you please help?
Has anyone found a workaround?
您好,我已收到您的邮件,并会尽快回复。This is an automatic reply, confirming that your e-mail was received.Thank you
I have the same issue, any workaround?
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.
您好,我已收到您的邮件,并会尽快回复。This is an automatic reply, confirming that your e-mail was received.Thank you