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

Fix repeated predefined rule on repeated field #150

Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ GOLANGCI_LINT_VERSION ?= v1.60.1
# Set to use a different version of protovalidate-conformance.
# Should be kept in sync with the version referenced in proto/buf.lock and
# 'buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go' in go.mod.
CONFORMANCE_VERSION ?= v0.8.1
CONFORMANCE_VERSION ?= v0.8.2

.PHONY: help
help: ## Describe useful make targets
Expand Down
4 changes: 2 additions & 2 deletions internal/constraints/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (c *Cache) Build(
fieldEnv, compileErr := env.Extend(
cel.Constant(
"rule",
celext.ProtoFieldToCELType(desc, true, forItems),
celext.ProtoFieldToCELValue(desc, rule, forItems),
celext.ProtoFieldToCELType(desc, true, false),
celext.ProtoFieldToCELValue(desc, rule, false),
Copy link
Member Author

Choose a reason for hiding this comment

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

Explanation for this just to make it extra clear: We don't want to propagate the forItems value here because it reflects if we're operating on a repeated element of the this field, not of the rule field. Instead, the only time forItems should be true for these specific calls should be when they recurse to get the inner element type/value. Otherwise, a repeated field with a predefined constraint applied will attempt to get the element type of the rule field itself, which does not make any sense.

),
)
if compileErr != nil {
Expand Down
Loading