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

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

Closed
akshukla25 opened this issue May 26, 2021 · 17 comments · Fixed by #2552

Comments

@akshukla25
Copy link

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."

@mikepizzo
Copy link
Member

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.

@Sreejithpin
Copy link
Contributor

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

@akshukla25
Copy link
Author

@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.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

@Sreejithpin
Copy link
Contributor

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

@akshukla25
Copy link
Author

Yes, mentioned assembly version in the description section.

@Sreejithpin
Copy link
Contributor

@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)

@akshukla25
Copy link
Author

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

@Sreejithpin
Copy link
Contributor

@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

@akshukla25
Copy link
Author

roleDef.zip

@vladascibulskis
Copy link

This is a duplicate reported in #1149

@akshukla25
Copy link
Author

@Sreejithpin is there any update on this issue?

@akshukla25
Copy link
Author

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

@spaasis
Copy link

spaasis commented Sep 28, 2022

Has anyone found a workaround?

@ycymio
Copy link

ycymio commented Sep 28, 2022 via email

@FirewizzNL
Copy link

I have the same issue, any workaround?

@vibatra
Copy link

vibatra commented Nov 7, 2022

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.

@ycymio
Copy link

ycymio commented Nov 7, 2022 via email

@xuzhg xuzhg self-assigned this Nov 8, 2022
xuzhg added a commit that referenced this issue Nov 11, 2022
…adata, its key and concurrency-token property values must be provided
xuzhg added a commit that referenced this issue Dec 7, 2022
…adata, its key and concurrency-token property values must be provided (#2552)

* issue #2098: fix the issue ODataException: To compute an entity's metadata, its key and concurrency-token property values must be provided

* Address the comments

* fix the issue: change the test condition for complex

* if the containment within complex property, we should reuse the existing odata path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment