Zac Morris
Zac Morris

Reputation: 1856

Breeze getValidationErrors not working?

A Breeze EntityMananger is throwing an exception when I try to save two related entities. The exception is being thrown client-side before any communication happens with the server. The error message in the exception is "Validation error", but calling EntityAspect.getValidationError() on each entity listed in the exception returns an empty array.

The screenshot below shows a live example:

enter image description here

Question: Is there some other way of finding out what exactly the validation problem is or is this a bug?

Thanks for your time!

Upvotes: 1

Views: 354

Answers (1)

Zac Morris
Zac Morris

Reputation: 1856

I found the cause of the behavior. rejectChanges() is called on the EntityManager for the entities in question before the exception raised by saveChanges() is rethrown, to be handled by the code in the example above. The error state of the entities is not preserved in the exception object, so calling getValidationErrors() on each entity after calling rejectChanges() returns an empty array since at that point the changes have been rolled back and there technically aren't any errors on the entity.

So, technically not a bug. Breeze is working as designed. However, I think there's an argument to be made that the exception object passed when saveChanges() fails should contain a complete and immutable description of the problem(s) that caused the exception.

Upvotes: 1

Related Questions