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

Incomplete JSON output is returned when querying navigation property that has at least one complex property. #760

Open
danleydmello opened this issue Dec 1, 2022 · 6 comments
Assignees
Labels
bug Something isn't working P2

Comments

@danleydmello
Copy link
Contributor

Incomplete JSON output is returned when querying navigation property that has at least one complex property.

To reproduce the problem use ODataDynamicModel sample.

  1. In MyDataSource.cs, add EdmComplexType property to DetailInfo entity.
  2. Add some value to this complex property in CreateDetailInfo()

Now run this query :
http://localhost:4527/odata/mydatasource/Products(1)/DetailInfo

Note that output is truncated and does not include complex property of DetailInfo :

{"@odata.context":"http://localhost:4527/odata/mydatasource/$metadata#Products/ns.DetailInfo/$entity","ID":88,"Title":"abc_detailinfo" <no results after this>

I see this exception in debug:

_Microsoft.OData.ODataException
HResult=0x80131509
Message=The type 'ns.DetailInfo' does not inherit from and is not a base type of 'ns.Product'. The type of 'KeySegments' must be related to the Type of the EntitySet.
Source=Microsoft.OData.Core
StackTrace:
at Microsoft.OData.UriParser.ExceptionUtil.ThrowIfTypesUnrelated(IEdmType type, IEdmType secondType, String segmentName)
at Microsoft.OData.UriParser.KeySegment..ctor(IEnumerable1 keys, IEdmEntityType edmType, IEdmNavigationSource navigationSource) at Microsoft.OData.UriParser.ODataPathExtensions.AddKeySegment(ODataPath path, IEnumerable1 keys, IEdmEntityType edmType, IEdmNavigationSource navigationSource)
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.OData.ODataWriterCore.<>c__DisplayClass65_0.b__0()
at Microsoft.OData.TaskUtils.GetTaskForSynchronousOperation(Action synchronousOperation)
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.d__19.MoveNext() in D:\githubrepos\AspNetCoreOData\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs:line 839

This exception was originally thrown at this call stack:
[External Code]
Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteComplexPropertiesAsync(Microsoft.AspNetCore.OData.Formatter.Serialization.SelectExpandNode, Microsoft.AspNetCore.OData.Formatter.ResourceContext, Microsoft.OData.ODataWriter) in ODataResourceSerializer.cs_

Note: Complex type works when expanding the navigation property.

@danleydmello danleydmello added the bug Something isn't working label Dec 1, 2022
@xuzhg
Copy link
Member

xuzhg commented Dec 5, 2022

It is related to this PR: OData/odata.net#2552

@danleydmello
Copy link
Contributor Author

@xuzhg , thanks for the reference,.
Will it fix my issue once the odata.net PR gets merged? What timeline we are looking at for odata.net and Microsoft.AspNetCore.OData patch release with this fix?

@xuzhg
Copy link
Member

xuzhg commented Dec 14, 2022

We just released 7.13.0 ODL. But, it seems this version doesn't fix this issue.
We'd find resource to find the root cause and fix this issue.

@danleydmello
Copy link
Contributor Author

@xuzhg , Thanks for the update. Do you know if the problem is in odata.net library or its in AspNetOData core ?
Any idea what time frame we are looking at ?

@xuzhg
Copy link
Member

xuzhg commented Dec 14, 2022

So far, I think it's from odata.net lib. The problem is that we want to 'calculate' a path for each sub-complex property.

Because complex property could contain navigation property, we should need that path to 'calculate' the context path for navigation property again, even though we don't know whether the complex does have navigation property or not.

OData/odata.net#2552 fixes the problem for the containment navigation property. I'd like to spend time understanding the complex property.

@premiaware
Copy link

premiaware commented Jan 15, 2023

Hi, I have same issue in .net 6 and odata 8.0.12

I have this object

public class TelefonoDescrittivo
{
public string? Etichetta { get; set; }
}

public class Uffici2
{
}

public partial class UfficiExt : Uffici2
{
     public List<TelefonoDescrittivo>? Telefoni { get; set; }
}

in my Model declare:
builderWeb.EntitySet("Uffici2");
builderWeb.EntitySet("UfficiExt");
builderWeb.EntityType().DerivesFrom();

when in call my bonded function in the controller

https://localhost:7146/odata/landingpageimmobili/Ufficio

controller
.......
[HttpGet]
public IActionResult Ufficio()
{
UfficiExt ufficioExt = new UfficiExt();
return Ok(ufficioExt);
}
.......

and ufficio return type "UfficiExt" with complex data i receive this exception.

Microsoft.OData.ODataException: The type 'FastHomeDB.Models.UfficiExt' does not inherit from and is not a base type of 'FastHomeDB.Models.LandingPageImmobili'. The type of 'KeySegments' must be related to the Type of the EntitySet.
at Microsoft.OData.UriParser.ExceptionUtil.ThrowIfTypesUnrelated(IEdmType type, IEdmType secondType, String segmentName)
at Microsoft.OData.UriParser.ODataPathExtensions.AddKeySegment(ODataPath path, IEnumerable1 keys, IEdmEntityType edmType, IEdmNavigationSource navigationSource) 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.OData.TaskUtils.GetTaskForSynchronousOperation[TArg1,TArg2](Action2 synchronousOperation, TArg1 arg1, TArg2 arg2)
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteComplexPropertiesAsync(SelectExpandNode selectExpandNode, ResourceContext resourceContext, ODataWriter writer)
at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteResourceAsync(Object graph, ODataWriter writer, ODataSerializerContext writeContext, IEdmTypeReference expectedType)
at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectInlineAsync(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectAsync(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
at Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatterHelper.WriteToStreamAsync(Type type, Object value, IEdmModel model, ODataVersion version, Uri baseAddress, MediaTypeHeaderValue contentType, HttpRequest request, IHeaderDictionary requestHeaders, IODataSerializerProvider serializerProvider)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Same issue was present in old version odata.net

OData/odata.net#2092
Then with the following versions it is solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2
Projects
None yet
Development

No branches or pull requests

4 participants