documentcloud/backbone — Issue #1053: Why does Model._validate accept an attrs param if it ignores it?
Author: khiltd
Created: 2012-02-27 19:28:23+00:00
State: open

The comments state that _validate should `Run validation against a set of incoming attributes, returning `true` if all is well`, yet the first thing it does is obliterate what it's been passed by extending attrs to include every single attribute in the model object:

https://github.com/documentcloud/backbone/blob/master/backbone.js#L491

I can't say whether this is a good thing or a bad thing, but it's not what I would expect to happen by looking at the method signature and documentation. Validating everything all the time regardless of whether or not it's been changed seems a bit wasteful, and it makes unit testing validations more difficult than they need to be because you can't simply have a spy assert that the success callback hasn't been called after setting an invalid value. With this approach, the success callback may actually be called dozens of times before the one bad attribute you actually wanted to validate bombs out.