Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Uniqueness only works on lists of primitive values #63

Closed
mivanovcpd opened this issue Nov 14, 2023 · 1 comment
Closed

[BUG] Uniqueness only works on lists of primitive values #63

mivanovcpd opened this issue Nov 14, 2023 · 1 comment
Labels
Bug Something isn't working

Comments

@mivanovcpd
Copy link

Description

Messages in Protobuf have overridden equals method so they can usually be compared correctly.
Suppose we have the following:

message Person {
  optional string name = 1 [(buf.validate.field).required = true];
  optional string family = 2 [(buf.validate.field).required = true];
}
message Persons {
  repeated PersonName persons = 1 [(buf.validate.field).repeated.unique = true];
}

Steps to Reproduce

  1. Create the relevant proto file as described above and write a test to validate a message from the generated model.

Expected Behavior

The validation should work.

Actual Behavior

The validation fails because the protovalidate-java doesn't support unique constraint on non-primitive types.

Environment

  • Operating System: Linux
  • Version: Mint
  • Compiler/Toolchain: Kotlin
  • Protovalidate Version: 0.1.8

Possible Solution

Disable the restriction in the code and allow arbitrary things to be compared to ensure uniqueness.

@mivanovcpd mivanovcpd added the Bug Something isn't working label Nov 14, 2023
@pkwarren
Copy link
Member

This is documented in the validate schema and not specific to the Java implementation: https://github.com/bufbuild/protovalidate/blob/7c3e2e3847b75e892b49411c788c350c5e272288/proto/protovalidate/buf/validate/validate.proto#L3316-L3318

There is a similar but not identical issue reported upstream in the protovalidate repo: bufbuild/protovalidate#92. I'd suggest opening a feature request there as any changes would need to be first made there, then verified in conformance tests, and then make their way to all of the language implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants