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

ModelStateDictionary.CanAddErrors and MaxAllowedErrors do not match their descriptions #1891

Closed
dougbu opened this issue Jan 26, 2015 · 3 comments
Assignees
Milestone

Comments

@dougbu
Copy link
Member

dougbu commented Jan 26, 2015

a few inconsistencies in the ModelStateDictionary implementation and doc comments:

  • TryAddModelError() adds up to MaxAllowedErrors total, including the final TooManyModelErrorsException error
  • MaxAllowedErrors doc comments state you can call TryAddModelError() this many times "after which an error is thrown for further invocations". "after which" is off by one.
  • CanAddErrors is implemented so that true means the next TryAddModelError() call will change the number of errors, either because there's room for another error or because the next call will result in the TooManyModelErrorsException error. so true does not mean the call will definitely add the expected error.
  • CanAddErrors doc comments correctly state it is a flag that determines if the total number of added errors (given by <see cref="ErrorCount"/>) is fewer than <see cref="MaxAllowedErrors"/>. however the name implies something different.
@yishaigalatzer
Copy link
Contributor

We should fix CanAddErrors to return false when the next error being added is TooManyModelErrors.

Fix doc comment for MaxAllowedErrors (or add a remark).

The others are by design.

@yishaigalatzer yishaigalatzer added this to the 6.0.0-rc1 milestone Jan 27, 2015
@yishaigalatzer yishaigalatzer assigned rynowak and unassigned dougbu Jan 27, 2015
@yishaigalatzer
Copy link
Contributor

Combine it when you fix the other MaxModelErrors issue

rynowak added a commit that referenced this issue Jan 27, 2015
Changes here are all focused around MaxModelErrors on
ModelStateDictionary.

MaxAllowedErrors now defaults to 200 (same as options). This means that
constructing a new ModelStateDictionary with the default constructor will
use this default. There's a new constructor for creating a
MaxAllowedErrors with a non-default value.

The ControllerActionArgumentBinder is now responsible for setting the
value from options onto ActionContext.ModelState. This results in better
layering and guarantees the option is respected if someone uses
extensibility to call model binding.

ModelStateDictionary.CanAddErrors is renamed to MaxErrorsReached. We
wanted to change the behavior of this property, but realized that it's
very useful inside the model validation code, so opted to renamed.

There's also a bunch of doc cleanup inside ModelStateDictionary to
simplify things and improve clarity.
rynowak added a commit that referenced this issue Jan 27, 2015
Changes here are all focused around MaxModelErrors on
ModelStateDictionary.

MaxAllowedErrors now defaults to 200 (same as options). This means that
constructing a new ModelStateDictionary with the default constructor will
use this default. There's a new constructor for creating a
MaxAllowedErrors with a non-default value.

The ControllerActionArgumentBinder is now responsible for setting the
value from options onto ActionContext.ModelState. This results in better
layering and guarantees the option is respected if someone uses
extensibility to call model binding.

ModelStateDictionary.CanAddErrors is renamed to MaxErrorsReached. We
wanted to change the behavior of this property, but realized that it's
very useful inside the model validation code, so opted to renamed.

There's also a bunch of doc cleanup inside ModelStateDictionary to
simplify things and improve clarity.
rynowak added a commit that referenced this issue Jan 28, 2015
Changes here are all focused around MaxModelErrors on
ModelStateDictionary.

MaxAllowedErrors now defaults to 200 (same as options). This means that
constructing a new ModelStateDictionary with the default constructor will
use this default. There's a new constructor for creating a
MaxAllowedErrors with a non-default value.

The ControllerActionArgumentBinder is now responsible for setting the
value from options onto ActionContext.ModelState. This results in better
layering and guarantees the option is respected if someone uses
extensibility to call model binding.

ModelStateDictionary.CanAddErrors is renamed to MaxErrorsReached. We
wanted to change the behavior of this property, but realized that it's
very useful inside the model validation code, so opted to renamed.

There's also a bunch of doc cleanup inside ModelStateDictionary to
simplify things and improve clarity.
rynowak added a commit that referenced this issue Jan 29, 2015
Changes here are all focused around MaxModelErrors on
ModelStateDictionary.

MaxAllowedErrors now defaults to 200 (same as options). This means that
constructing a new ModelStateDictionary with the default constructor will
use this default. There's a new constructor for creating a
MaxAllowedErrors with a non-default value.

The ControllerActionArgumentBinder is now responsible for setting the
value from options onto ActionContext.ModelState. This results in better
layering and guarantees the option is respected if someone uses
extensibility to call model binding.

ModelStateDictionary.CanAddErrors is renamed to MaxErrorsReached. We
wanted to change the behavior of this property, but realized that it's
very useful inside the model validation code, so opted to renamed.

There's also a bunch of doc cleanup inside ModelStateDictionary to
simplify things and improve clarity.
@rynowak
Copy link
Member

rynowak commented Jan 29, 2015

42df4cf

@rynowak rynowak closed this as completed Jan 29, 2015
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

3 participants