Skip to content

in operator not working with null Guid values - #2035

Merged
ElizabethOkerio merged 3 commits into
OData:masterfrom
ElizabethOkerio:fix/1997_in_operator_not_working_with_null_guid_properties
May 5, 2021
Merged

ElizabethOkerio merged 3 commits into
OData:masterfrom
ElizabethOkerio:fix/1997_in_operator_not_working_with_null_guid_properties

Conversation

@ElizabethOkerio

@ElizabethOkerio ElizabethOkerio commented Mar 24, 2021 •

Copy link
Copy Markdown
Contributor

Issues

This pull request fixes issue #1997 .

Description

Briefly describe the changes of this pull request.

For a sample model like the one shown below

public class TestEntity
{
   public guid? NullableProperty { get; set; }
}

Running the following sample query throws an error.
It is also been clear that a null GUID should not be equated to an empty GUID.

http://host/service/TestEntity?$filter=NullableProperty in (null)

Guid literals are converted to single-quoted form, so that they are compatible with the Json reader used for deserialization.

Sample: [D01663CF-EB21-4A0E-88E0-361C10ACE7FD, 492CF54A-84C9-490C-A7A4-B5010FAD8104]
==>  ['D01663CF-EB21-4A0E-88E0-361C10ACE7FD', '492CF54A-84C9-490C-A7A4-B5010FAD8104']

This means that even null GUIDS will be converted to the single quoted form which will later lead to them being processed as null strings. ("null").

Sample: [null, null]
==>  ['null', 'null']

This fix ensures that null GUIDs are not converted to the single-quoted form and are processed as null values.

Sample: [null] ==>  [null]

Checklist (Uncheck if it is not completed)

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

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

@ElizabethOkerio
ElizabethOkerio force-pushed the fix/1997_in_operator_not_working_with_null_guid_properties branch from 4993a15 to 9362cb6 Compare March 25, 2021 06:26
@ElizabethOkerio ElizabethOkerio added Ready for review Use this label if a pull request is ready to be reviewed and removed draft labels Mar 26, 2021
Comment thread src/Microsoft.OData.Core/ODataPayloadValueConverter.cs Outdated
@habbes

habbes commented Mar 26, 2021

Copy link
Copy Markdown
Contributor

Could you add test cases for this?

Comment thread src/Microsoft.OData.Core/UriParser/Binders/InBinder.cs Outdated
Comment thread src/Microsoft.OData.Core/UriParser/Binders/InBinder.cs Outdated
@gathogojr

Copy link
Copy Markdown
Contributor

Please add tests

@ElizabethOkerio
ElizabethOkerio force-pushed the fix/1997_in_operator_not_working_with_null_guid_properties branch 2 times, most recently from 5846cb8 to c3500d9 Compare May 4, 2021 12:27

@gathogojr gathogojr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but I have to wonder if the issue could have been resolved by changing this:

if (items[i][0] != '\'' && items[i][0] != '"')

to

if (items[i] != "null" && items[i][0] != '\'' && items[i][0] != '"')

Kindly confirm if that would do the job

@xuzhg xuzhg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@ElizabethOkerio

Copy link
Copy Markdown
Contributor Author

Looks good to me but I have to wonder if the issue could have been resolved by changing this:

if (items[i][0] != '\'' && items[i][0] != '"')

to

if (items[i] != "null" && items[i][0] != '\'' && items[i][0] != '"')

Kindly confirm if that would do the job

We still need the else part:

if (items[i] != "null" && items[i][0] != '\'' && items[i][0] != '"')
{
}
else if(items[i] == "null")
{

} 

Because we need to assign the items[i]. And for the check we have to specify that it is a null coz it could be anything else that does not meet the first criteria.

@gathogojr

Copy link
Copy Markdown
Contributor

Looks good to me but I have to wonder if the issue could have been resolved by changing this:

if (items[i][0] != '\'' && items[i][0] != '"')

to

if (items[i] != "null" && items[i][0] != '\'' && items[i][0] != '"')

Kindly confirm if that would do the job

We still need the else part:

if (items[i] != "null" && items[i][0] != '\'' && items[i][0] != '"')
{
}
else if(items[i] == "null")
{

} 

Because we need to assign the items[i]. And for the check we have to specify that it is a null coz it could be anything else that does not meet the first criteria.

Maybe I don't understand, but why would we need the else part? Assigning items[i] to items[i] is the same as leaving items[i] untouched and that would be accomplished by the check if (items[i] != "null"..., no?
I may not have full visibility though so I could be missing something

@ElizabethOkerio

Copy link
Copy Markdown
Contributor Author

Looks good to me but I have to wonder if the issue could have been resolved by changing this:

if (items[i][0] != '\'' && items[i][0] != '"')

to

if (items[i] != "null" && items[i][0] != '\'' && items[i][0] != '"')

Kindly confirm if that would do the job

We still need the else part:

if (items[i] != "null" && items[i][0] != '\'' && items[i][0] != '"')
{
}
else if(items[i] == "null")
{

} 

Because we need to assign the items[i]. And for the check we have to specify that it is a null coz it could be anything else that does not meet the first criteria.

Maybe I don't understand, but why would we need the else part? Assigning items[i] to items[i] is the same as leaving items[i] untouched and that would be accomplished by the check if (items[i] != "null"..., no?
I may not have full visibility though so I could be missing something

Yes I get

@ElizabethOkerio
ElizabethOkerio force-pushed the fix/1997_in_operator_not_working_with_null_guid_properties branch from 8272d5d to 2ffa3b7 Compare May 5, 2021 05:33
@pull-request-quantifier-deprecated

Copy link
Copy Markdown

This PR has 6 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Extra Small
Size       : +3 -3
Percentile : 2.4%

Total files changed: 2

Change summary by file extension:
.cs : +3 -3

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@ElizabethOkerio
ElizabethOkerio merged commit 2eb6c96 into OData:master May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Extra Small Ready for review Use this label if a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants