Skip to content

v0.6.0

Compare
Choose a tag to compare
@jchadwick-buf jchadwick-buf released this 12 Dec 16:35
· 74 commits to main since this release
5e6ac7b

Breaking Changes

protovalidate.ValidationError has changed. The violations property is now a list of protovalidate.Violation, instead of a protobuf buf.validate.Violations message. In most cases, code will need to be updated like this:

     violations = protovalidate.collect_violations(msg)
-    print(violations.violations[0].constraint_id)
+    print(violations[0].proto.constraint_id)

The ValidationError.errors() method is removed in favor of the violations property, and a new ValidationError.to_proto() method is added to return the equivalent buf.validate.Violations.


In addition to containing the buf.validate.Violation protobuf message under the property proto, the new protovalidate.Violation class contains additional in-memory information about the violation which cannot be serialized to the wire:

  • field_value: Contains the value of the field failing validation, if there is a field corresponding to the violation.
  • rule_value: Contains the value of the rule failing validation, if there is a rule corresponding to the violation.

Take, for example, the following protobuf message schema:

message User {
    string email = 1 [(buf.validate.field).string.email = true];
}

If you try to validate the message User(email="invalid"), the field_value will be "invalid" and the rule_value will be True.

Some violations do not correspond directly to a field, such as a message constraint failure; in these cases, the field_value will be None.

What's Changed

Full Changelog: v0.5.0...v0.6.0