Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gen/tests/example/v1/validations_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions gen/tests/example/v1/validations_pb2.pyi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions proto/tests/example/v1/validations.proto
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,16 @@ message RepeatedEmbedSkip {
message InvalidRESyntax {
string value = 1 [(buf.validate.field).string.pattern = "^\\z"];
}

// via #353.

message ConcatenatedValues {
option (buf.validate.message).cel = {
id: "globally_unique_names"
message: "all values in bar and baz must be globally unique"
expression: "(this.bar + this.baz).unique()"
};

repeated string bar = 1;
repeated string baz = 2;
}
2 changes: 1 addition & 1 deletion protovalidate/internal/extra_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def cel_is_inf(val: celtypes.Value, sign: typing.Optional[celtypes.Value] = None


def cel_unique(val: celtypes.Value) -> celpy.Result:
if not isinstance(val, celtypes.ListType):
if not isinstance(val, celtypes.ListType) and not isinstance(val, list):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not isinstance(val, (celtypes.ListType, list)) would have worked here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yeah, that's a little nicer. feel free to PR!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to. #357 is up if you'd like to take a look.

msg = "invalid argument, expected list"
raise celpy.CELEvalError(msg)
return celtypes.BoolType(len(val) == len(set(val)))
Expand Down
8 changes: 8 additions & 0 deletions test/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ def test_multiple_validations(self):

self._run_invalid_tests(msg, [expected_violation1, expected_violation2])

def test_concatenated_values(self):
msg = validations_pb2.ConcatenatedValues(
bar=["a", "b", "c"],
baz=["d", "e", "f"],
)

self._run_valid_tests(msg)

def test_fail_fast(self):
"""Test that fail fast correctly fails on first violation

Expand Down