Skip to content

Commit 6b59c4e

Browse files
Fix instance check for concatenated values (#354)
Fixes #353.
1 parent 9d5b9e8 commit 6b59c4e

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

gen/tests/example/v1/validations_pb2.py

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/tests/example/v1/validations_pb2.pyi

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/tests/example/v1/validations.proto

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,16 @@ message RepeatedEmbedSkip {
111111
message InvalidRESyntax {
112112
string value = 1 [(buf.validate.field).string.pattern = "^\\z"];
113113
}
114+
115+
// via #353.
116+
117+
message ConcatenatedValues {
118+
option (buf.validate.message).cel = {
119+
id: "globally_unique_names"
120+
message: "all values in bar and baz must be globally unique"
121+
expression: "(this.bar + this.baz).unique()"
122+
};
123+
124+
repeated string bar = 1;
125+
repeated string baz = 2;
126+
}

protovalidate/internal/extra_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def cel_is_inf(val: celtypes.Value, sign: typing.Optional[celtypes.Value] = None
332332

333333

334334
def cel_unique(val: celtypes.Value) -> celpy.Result:
335-
if not isinstance(val, celtypes.ListType):
335+
if not isinstance(val, celtypes.ListType) and not isinstance(val, list):
336336
msg = "invalid argument, expected list"
337337
raise celpy.CELEvalError(msg)
338338
return celtypes.BoolType(len(val) == len(set(val)))

test/test_validate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ def test_multiple_validations(self):
179179

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

182+
def test_concatenated_values(self):
183+
msg = validations_pb2.ConcatenatedValues(
184+
bar=["a", "b", "c"],
185+
baz=["d", "e", "f"],
186+
)
187+
188+
self._run_valid_tests(msg)
189+
182190
def test_fail_fast(self):
183191
"""Test that fail fast correctly fails on first violation
184192

0 commit comments

Comments
 (0)