bufbuild / buf

The best way of working with Protocol Buffers.

Home Page:https://buf.build

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issues with protovalidate when linting a proto file with repeated fields and protovalidate constraints

Hunterlige opened this issue · comments

Recent versions of buf produce error messages with protovalidate repeated fields.

v1.26 works fine and does not produce those error messages
v1.28 works fine and does not produce those error messages
v1.29 produces those error messages
v1.30 produces those error messages

To reproduce:

message IPAllowlist {
  repeated string allow_cidr = 1 [(buf.validate.field).repeated = {
    min_items: 1,
    items: {
      cel: [
        {
          id: "ip_prefix",
          message: "value must be IPv4 prefix",
          expression: "this.isIpPrefix(4, true)",
        }
      ],
    },
  }];
}

The full proto file can be found in the protovalidate examples folder https://github.com/bufbuild/protovalidate/blob/main/examples/cel_field_repeated.proto

Run the linter. I used buf lint

(buf.validate.field).repeated.items.cel.expression on field "allow_cidr" fails to compile: found no matching overload for 'isIpPrefix' applied to 'list(string).(int, bool)'
 | this.isIpPrefix(4, true)
 | ...............

A workaround is to disable the PROTOVALIDATE rules but this is not ideal,

I believe we fixed this in #2824 and need to do a release for it, we'll get on it.

This is in v1.30.1.