Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

$it wrong implementation #1432

Open
Xriuk opened this issue Mar 6, 2025 · 3 comments
Open

$it wrong implementation #1432

Xriuk opened this issue Mar 6, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Xriuk
Copy link

Xriuk commented Mar 6, 2025

I think that $it meaning is misenterpreted in the current implementation.

From the specs (5.1.1.14.4) (emphasis mine):

The $it literal can be used in expressions to refer to the current instance of the resource identified by the resource path.

And the examples clarify that well:
Here $it refers to the current element of the primitive collection resource "EmailAddresses"

http://host/service/Customers(1)/EmailAddresses?$filter=endswith($it,'.com')

And here $it refers to the current Customer entity of the entity set resource "Customers"

http://host/service/Customers?$expand=Orders($filter=$it/Address/City eq ShipTo/City)

However if I use the second URL I get the following error:

Instance property 'Address' is not defined for type '[...].Order' (Parameter 'propertyName')

So it seems that it treats $it as the element of the current collection, which is what $this is supposed to be for.

This also happens for complex collection properties.

This is backed by the following blog post: https://devblogs.microsoft.com/odata/select-enhancement-in-asp-net-core-odata/
Which also uses $it wrongly in all the examples instead of $this.

Also from the specs (5.1.1.14.6):

$this ... It refers to the current instance of the collection.

While $this seems to be supported it is not mentioned anywhere, and $it seems like an alias for it (in fact they produce identical resuls), while it should be totally different.

In the end $it should only refer to the root collection/element which is the one represented by the resource path.

@Xriuk Xriuk added the bug Something isn't working label Mar 6, 2025
@corranrogue9
Copy link
Contributor

corranrogue9 commented Mar 11, 2025

Thanks, your understanding is correct. From our triage meeting, we had the following note:

This seems related to the query option context binder. We need to transfer the $it lambda to the child from the parent.

@corranrogue9
Copy link
Contributor

We need to make sure that we introduce a compatibility flag so that customer clients who are perhaps misusing $it or $this are not going to be broken as a result of the fix.

@xuzhg
Copy link
Member

xuzhg commented Mar 11, 2025

Hello, @Xriuk
I tried to reproduce the issue, but it seems it works fine at my side. Let me share what I did and hope you can find the gap or maybe you can share a reproduce for me to dig more.

You can find my sample here

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

No branches or pull requests

3 participants