v0.6.0
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
- Regenerate protos by @stefanvanburen in #198
- Update README for buf v2 commands/config by @stefanvanburen in #197
- Bump generated code to latest version by @stefanvanburen in #201
- Add explicit Python 3.13 support by @stefanvanburen in #204
- Bump mypy from 1.11.1 to 1.13.0 by @dependabot in #207
- Drop Python 3.8 support by @stefanvanburen in #209
- Update protovalidate to v0.8.2 by @jchadwick-buf in #216
- Bump tomli from 2.0.2 to 2.1.0 by @dependabot in #214
- Implement structured field and rule paths for violations by @jchadwick-buf in #217
- Bump ruff from 0.5.5 to 0.8.1 by @dependabot in #219
- Bump pytest from 8.3.2 to 8.3.4 by @dependabot in #222
- Bump tomli from 2.1.0 to 2.2.1 by @dependabot in #221
- Bump protobuf from 5.27.3 to 5.29.0 by @dependabot in #220
- Add rule and field value to violations by @jchadwick-buf in #224
Full Changelog: v0.5.0...v0.6.0