You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm updating protovalidate used in my Go/Java/Python applications to the latest versions, and encountered an inconsistent behavior, but I couldn't determine if it's a bug or it's an expected behavior as I can't find any example that resembles my use case.
My use case of cel validation is to apply string functions to validate a list of strings. For example, I used an expression similar to the message below to achieve what I need:
My understanding was that the variable this refers to each single item in a repeated field, so in this case I supposed it should be a string. This works well in protovalidate for Java/Python even with the latest releases, but not with protovalidate-go. The change happened in #80 is the cause of my issue here. With protovalidate-go >= v0.4.2, the following code produces an error on the type of the string function I want to apply.
compilation error: failed to compile items constraints for repeated mytest.TestRepeatedOne.paths: compilation error: failed to compile expression : ERROR: <input>:1:17: found no matching overload for 'startsWith' applied to 'list(string).(string)'
I briefly checked underlying code and thought the this variable here now resolves to the list itself rather than individual items, so tried this:
for the same validation. The validation errors produces from this approach however don't contain the information about which item in the list fails, while items.cel could hint it. As such, I'd still like to know what's the correct way to compose such expressions. I ask this question here instead of bufbuild/protovalidate-go is that I'm not sure this is a spec problem or a bug in the Go implementation. If my understanding in TestRepeatedOne is correct, then probably this counts a bug in the Go implementation, and I can move this issue there.
The test results for the same messages on protovalidate-python and protovalidate-java are attached by the way:
[email protected]: All three messages passed, although it looks like that the expression in TestRepeatedTwo resolved this as a single string and the x in the all macro is actually characters in the string.
[email protected]: TestRepeatedTwo failed to compile(Failed to compile expression), but I guess that's expected. TestRepeatedOne works as expected.
The text was updated successfully, but these errors were encountered:
Hey, @falau! Thanks for the very detailed report. I'm going to move this to protovalidate-go as you actually caught a bug in how we construct the validations internally. You are correct that the issue is related to how the variable types are computed.
Description
Hello, I'm updating
protovalidate
used in my Go/Java/Python applications to the latest versions, and encountered an inconsistent behavior, but I couldn't determine if it's a bug or it's an expected behavior as I can't find any example that resembles my use case.My use case of cel validation is to apply string functions to validate a list of strings. For example, I used an expression similar to the message below to achieve what I need:
My understanding was that the variable
this
refers to each single item in a repeated field, so in this case I supposed it should be astring
. This works well in protovalidate for Java/Python even with the latest releases, but not withprotovalidate-go
. The change happened in #80 is the cause of my issue here. Withprotovalidate-go
>= v0.4.2, the following code produces an error on the type of the string function I want to apply.The error is
I briefly checked underlying code and thought the
this
variable here now resolves to the list itself rather than individual items, so tried this:However, it also gives error:
so my assumption about the passed in type is wrong.
I know I can always use a message level validator like this:
for the same validation. The validation errors produces from this approach however don't contain the information about which item in the list fails, while
items.cel
could hint it. As such, I'd still like to know what's the correct way to compose such expressions. I ask this question here instead of bufbuild/protovalidate-go is that I'm not sure this is a spec problem or a bug in the Go implementation. If my understanding inTestRepeatedOne
is correct, then probably this counts a bug in the Go implementation, and I can move this issue there.Environment
Additional Context
The test results for the same messages on protovalidate-python and protovalidate-java are attached by the way:
TestRepeatedTwo
resolvedthis
as a single string and thex
in theall
macro is actually characters in the string.TestRepeatedTwo
failed to compile(Failed to compile expression
), but I guess that's expected.TestRepeatedOne
works as expected.The text was updated successfully, but these errors were encountered: