OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

Misleading error message for $expand on non-navigation property #2831

Open syprieur opened 9 months ago

syprieur commented 9 months ago

When an $expand is run against a valid non-navigation property of the type, the error message emitted by ODL has been reported by customers as misleading.

Assemblies affected

All Microsoft.OData.Core up to 7.19 included.

Reproduce steps

With:

The incorrect query: /calendars?$expand=owner yields the error message:

Property 'owner' on type 'microsoft.graph.calendar' is not a navigation property or complex property. Only navigation properties can be expanded.

This is somewhat misleading, as owner is a complex property of the type microsoft.graph.calendar.

Additional detail

The error message comes from ExpandItemBinder_PropertyIsNotANavigationPropertyOrComplexProperty. The intent behind mentioning complex properties is unknown. Was it to allow valid expand paths traversing complex properties?

habbes commented 9 months ago

I'm not sure why the error message specifies both a navigation property or complex property. It appears that in the past this error message only referred to navigation properties but 7 years ago a change was introduced that added the "complex property" to the message: https://github.com/OData/odata.net/commit/24b9727f24c28589c32b891d35ac20d730b55850

My guess is that this error message is used in a different places and maybe in some of those places it applies to both navigation properties and complex properties and they decided to update the error message as a result. Maybe we should add an error message that only applies to navigation properties to use in scenarios that do not apply to complex properties.