Skip to content

[Validator] fix comparisons with null values at property paths #29839

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

Merged
merged 1 commit into from
Dec 16, 2019

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Jan 10, 2019

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #29831
License MIT
Doc PR

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

@xabbuh Can you finish this one?

@xabbuh
Copy link
Member Author

xabbuh commented Jul 8, 2019

I think we need to make a decision first how we see null values should be handled. IMO comparing null with greater or less than operators doesn't make any sense.

@fabpot
Copy link
Member

fabpot commented Jul 8, 2019

@xabbuh I agree that comparing null with these operators do not make sense.

@castroCrea
Copy link

?

@xabbuh
Copy link
Member Author

xabbuh commented Oct 15, 2019

@symfony/mergers How do we proceed here? Does a comparison with null always lead to a true or a false result? Throwing an exception would be logical, but isn't possible without breaking backwards compatibility.

@ogizanagi
Copy link
Contributor

ogizanagi commented Oct 15, 2019

How do we proceed here? Does a comparison with null always lead to a true or a false result? Throwing an exception would be logical, but isn't possible without breaking backwards compatibility.

To me null values should be ignored. If any is encountered, we should skip the comparison as it makes no sense.
Throwing is not required if the property is allowed to be null. If it isn't, the proper @NotNull constraint should have been set in the first place.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 15, 2019

Throwing is not required if the property is allowed to be null. If it isn't, the proper @NotNull constraint should have been set in the first place.

Well, this is not about the property the constraint is attached too. But if you compare it to another property that one can be null too.

But to make it a bit more clear what I mean: My reasoning would be that a null value should never raise a validation constraint and the comparison constraints should reflect that.

@sgehrig
Copy link
Contributor

sgehrig commented Oct 15, 2019

Just my two cents because I originally raised the issue (#29831).

I'd assume that, if the value returned by propertyPath is null, the validator will just ignore the comparison. Just as the validator ignores the comparison if the owning side value (that's where the constraint is attached to) is null.

But this may not be correct when dealing with the Equal/NotEqual/IdenticalTo/NotIdenticalTo as pointed out by @xabbuh in #29831 (comment).

So I think to address this correctly, there needs to be a different handling for the equal/not-equal constraints. But for the less-than/greater-than (-equals) constraints a comparison with null should be ignored.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 15, 2019

@sgehrig Yes, that pretty much sums up my thoughts.

@xabbuh
Copy link
Member Author

xabbuh commented Oct 15, 2019

Status: Needs Review

@xabbuh
Copy link
Member Author

xabbuh commented Oct 31, 2019

ping @symfony/mergers

xabbuh added a commit that referenced this pull request Dec 16, 2019
…aths (xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Validator] fix comparisons with null values at property paths

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29831
| License       | MIT
| Doc PR        |

Commits
-------

ffa5db7 fix comparisons with null values at property paths
@xabbuh xabbuh merged commit ffa5db7 into symfony:3.4 Dec 16, 2019
@xabbuh xabbuh deleted the issue-29831 branch December 16, 2019 08:56
This was referenced Dec 19, 2019
This was referenced Jan 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants