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

Fix argument null exception during projection #3038

Merged
merged 4 commits into from
Aug 19, 2024

Conversation

uffelauesen
Copy link
Contributor

Issues

This pull request fixes #3037.

Description

Fixes issue in ProjectionValueForPath() when linkEntry.Properties is null bypassing call to OfType().

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

Regression introduced in ODL Client 8.0.0-rc.1

@uffelauesen uffelauesen changed the title Fix argument null exception during Fix argument null exception during projection Aug 15, 2024
@habbes
Copy link
Contributor

habbes commented Aug 15, 2024

Thanks for the catch. This must be due to change from ODataProperty to ODataPropertyInfo. I'm surprised no tests failed because of this. But most of client query tests are in E2E tests which are still being ported over. @ElizabethOkerio have we ported any E2E tests that perform a projection?

@habbes habbes requested a review from gathogojr August 15, 2024 14:12
@habbes
Copy link
Contributor

habbes commented Aug 15, 2024

The issue was introduced by this PR: #2916

The root issue is that ODataResource.Properties and MaterializerEntry.Properties could be null. So may have other places that could break. We should consider adding the null check here as well: https://github.com/OData/odata.net/pull/2916/files#diff-a39b2ec2693141c7a1e515c2b9ca95fb0fd0b3eacc903b92e61a048d07738fe0R253

gathogojr
gathogojr previously approved these changes Aug 16, 2024
@habbes
Copy link
Contributor

habbes commented Aug 16, 2024

Thanks @gathogojr for adding the tests

@gathogojr
Copy link
Contributor

More details from the investigation:

var serviceRoot = new Uri("http://localhost:5205");
var ctx = new Container(serviceRoot);

var query1 = from people in ctx.People
            where people.Spouse == null
            select new Person
            {
                Id = people.Id,
                Spouse = people.Spouse
            };
// OData URL: http://localhost:5205/People?$filter=Spouse eq null&$expand=Spouse&$select=Id
var results1 = query1.ToList(); // Throws exception

var query2 = ctx.CreateQuery<Person>("People").Where(p1 => p1.Spouse == null).Select(p2 => new { p2.Id, p2.Spouse });
// OData URL: http://localhost:5205/People?$filter=Spouse eq null&$expand=Spouse&$select=Id
var results2 = query2.ToList(); // Throws exception

var query3 = ctx.People.AddQueryOption("$filter", "Spouse eq null").AddQueryOption("$expand", "Spouse").AddQueryOption("$select", "Id");
// OData URL: http://localhost:5205/People?$expand=Spouse&$filter=Spouse eq null&$select=Id
var results3 = query3.ToList(); // No exception thrown

var query4 = ctx.Execute<Person>(new Uri("http://localhost:5205/People?$expand=Spouse&$filter=Spouse eq null&$select=Id"));
// OData URL: http://localhost:5205/People?$expand=Spouse&$filter=Spouse eq null&$select=Id
var results4 = query4.ToList(); // No exception thrown

var query5 = ctx.Execute<Person>(new Uri("http://localhost:5205/People?$filter=Spouse eq null&$expand=Spouse&$select=Id"));
// OData URL: http://localhost:5205/People?$filter=Spouse eq null&$expand=Spouse&$select=Id
var results5 = query5.ToList(); // No exception thrown! Yet the OData URL mirrors that of the first two query expressions. Projection seems to be where the issue is

@gathogojr gathogojr merged commit 648c169 into OData:main Aug 19, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client 8.0.0 - Projection fails for navigation property being null
3 participants