You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
We have an integration test that demonstrates this issue. See: FromBodyAndRequiredOnValueTypeProperty_EmptyBody_JsonFormatterAddsModelStateError
In reality, this is two bugs that wipe each other out. The validation node created by the body model binder, shouldn't be used/validated/created because there was no value set on the model. However, because we look at the model property and not at the validation node, we work around the bug in the validation or don't get an extra validation error.
The call to GetPropertyExplorer@182 ignores the value in the node.
We should consider a design where these validation nodes don't get created. The extra node that was created has no information that we don't already have in the system. We really only need validation nodes when model binding uses collections.
The model looks like this:
public class Person4
{
[Required]
[FromBody]
public int Address { get; set; }
}
In this testcase, no body is submitted in the request, so the Address property has the default value of 0. However the model validation node for Address is created with a null model value. Validation then ignores the value set on the validation node and uses the property value instead.
The text was updated successfully, but these errors were encountered:
We have an integration test that demonstrates this issue. See:
FromBodyAndRequiredOnValueTypeProperty_EmptyBody_JsonFormatterAddsModelStateError
In reality, this is two bugs that wipe each other out. The validation node created by the body model binder, shouldn't be used/validated/created because there was no value set on the model. However, because we look at the model property and not at the validation node, we work around the bug in the validation or don't get an extra validation error.
See: https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Validation/DefaultObjectValidator.cs#L182
The call to
GetPropertyExplorer@182
ignores the value in the node.We should consider a design where these validation nodes don't get created. The extra node that was created has no information that we don't already have in the system. We really only need validation nodes when model binding uses collections.
The model looks like this:
In this testcase, no body is submitted in the request, so the
Address
property has the default value of0
. However the model validation node forAddress
is created with anull
model value. Validation then ignores the value set on the validation node and uses the property value instead.The text was updated successfully, but these errors were encountered: