Why are properties with validation errors removed from the entity properties?

I noticed that properties of entites are being removed (!) from the entity itself (before saving) when they contain validation errors. Instead they are moved to the protected “[invalid]” property.

Is this a bug, or intended behavior?

This doesn’t make any sense to me. Shouldn’t the entity model remain consistent even if the property does not pass validation?

The documentation states _invalid: “List of invalid fields and their data for errors upon validation/patching”. This isn’t true at least for “requirePresence” and ->setError(). In this case the invalid fields aren’t listed.

Am I misunderstanding something?

I’m using cakephp 3.4.

Ok this seems the intended behavior.

The documentation states:

The fields with errors will not be present in the returned entity

See: Validating Data - 3.10

A reason i can imagine is that if for ex.: a field has the wrong type it should not further processed for consistency reasons. If the field with the wrong type is part of the entity (before saving) your entity is invalid anyway.