Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Validation ignores ValidationNode.Model when the node represents a model property #2784

Closed
rynowak opened this issue Jul 6, 2015 · 1 comment

Comments

@rynowak
Copy link
Member

rynowak commented Jul 6, 2015

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:

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.

@danroth27 danroth27 added this to the 6.0.0-beta7 milestone Jul 20, 2015
@rynowak rynowak modified the milestones: 6.0.0-beta8, 6.0.0-beta7 Aug 14, 2015
@rynowak
Copy link
Member Author

rynowak commented Sep 28, 2015

This is addressed in the new validation system: 8a502db

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants