Skip to content

Commit e3bc41a

Browse files
author
John Chadwick
committed
Update to pass latest conformance
1 parent cfb7582 commit e3bc41a

File tree

6 files changed

+70
-42
lines changed

6 files changed

+70
-42
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ADD_LICENSE_HEADER := $(BIN)/license-header \
1717
--copyright-holder "Buf Technologies, Inc." \
1818
--year-range "2023"
1919
# TODO: DO NOT MERGE
20-
PROTOVALIDATE_VERSION ?= 9fbcb20937fb97609f5711d25474213241694294
20+
PROTOVALIDATE_VERSION ?= a4d7e113cc9e8944fb22098123eddc5413500381
2121

2222
.PHONY: help
2323
help: ## Describe useful make targets
@@ -35,8 +35,9 @@ clean: ## Delete intermediate build artifacts
3535
generate: $(BIN)/buf $(BIN)/license-header ## Regenerate code and license headers
3636
rm -rf gen
3737
# TODO: DO NOT MERGE
38-
buf generate buf.build/jchadwick-buf/protovalidate:6ecee89ee0c94599abc6a872387cd5ed
39-
buf generate buf.build/bufbuild/protovalidate-testing:v0.8.2
38+
buf generate buf.build/jchadwick-buf/protovalidate:fd74cad4128d4294812fe3ad3fac0e2f
39+
# TODO: DO NOT MERGE
40+
buf generate buf.build/jchadwick-buf/protovalidate-testing:4b978585a3ae4589a2bf979580e0cf51
4041
$(ADD_LICENSE_HEADER) --ignore __init__.py
4142

4243
.PHONY: format

gen/buf/validate/conformance/cases/custom_constraints/custom_constraints_pb2.py

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

gen/buf/validate/conformance/cases/custom_constraints/custom_constraints_pb2.pyi

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

gen/buf/validate/validate_pb2.py

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

gen/buf/validate/validate_pb2.pyi

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

protovalidate/internal/constraints.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,22 @@ def _oneof_to_element(oneof: descriptor.OneofDescriptor) -> validate_pb2.FieldPa
198198

199199

200200
def _set_path_element_map_key(
201-
element: validate_pb2.FieldPathElement, key: typing.Any, key_field: descriptor.FieldDescriptor
201+
element: validate_pb2.FieldPathElement,
202+
key: typing.Any,
203+
key_field: descriptor.FieldDescriptor,
204+
value_field: descriptor.FieldDescriptor,
202205
):
206+
element.key_type = key_field.type
207+
element.value_type = value_field.type
203208
if key_field.type == descriptor.FieldDescriptor.TYPE_BOOL:
204209
element.bool_key = key
205-
elif key_field.type in (descriptor.FieldDescriptor.TYPE_SINT32, descriptor.FieldDescriptor.TYPE_SINT64):
206-
element.sint_key = key
207210
elif key_field.type in (
208211
descriptor.FieldDescriptor.TYPE_INT32,
209212
descriptor.FieldDescriptor.TYPE_SFIXED32,
210213
descriptor.FieldDescriptor.TYPE_INT64,
211214
descriptor.FieldDescriptor.TYPE_SFIXED64,
215+
descriptor.FieldDescriptor.TYPE_SINT32,
216+
descriptor.FieldDescriptor.TYPE_SINT64,
212217
):
213218
element.int_key = key
214219
elif key_field.type in (
@@ -390,8 +395,18 @@ class FieldConstraintRules(CelConstraintRules):
390395
validate_pb2.FieldConstraints.DESCRIPTOR.fields_by_number[
391396
validate_pb2.FieldConstraints.REQUIRED_FIELD_NUMBER
392397
]
393-
),
394-
],
398+
)
399+
]
400+
)
401+
402+
_cel_rule_path: typing.ClassVar[validate_pb2.FieldPath] = validate_pb2.FieldPath(
403+
elements=[
404+
_field_to_element(
405+
validate_pb2.FieldConstraints.DESCRIPTOR.fields_by_number[
406+
validate_pb2.FieldConstraints.CEL_FIELD_NUMBER
407+
]
408+
)
409+
]
395410
)
396411

397412
def __init__(
@@ -438,8 +453,11 @@ def __init__(
438453
]
439454
),
440455
)
441-
for cel in field_level.cel:
442-
self.add_rule(env, funcs, cel)
456+
for i, cel in enumerate(field_level.cel):
457+
rule_path = validate_pb2.FieldPath()
458+
rule_path.CopyFrom(self._cel_rule_path)
459+
rule_path.elements[0].index = i
460+
self.add_rule(env, funcs, cel, rule_path=rule_path)
443461

444462
def validate(self, ctx: ConstraintContext, message: message.Message):
445463
if _is_empty_field(message, self._field):
@@ -702,7 +720,8 @@ def validate(self, ctx: ConstraintContext, message: message.Message):
702720
if map_ctx.has_errors():
703721
element = _field_to_element(self._field)
704722
key_field = self._field.message_type.fields_by_name["key"]
705-
_set_path_element_map_key(element, k, key_field)
723+
value_field = self._field.message_type.fields_by_name["value"]
724+
_set_path_element_map_key(element, k, key_field, value_field)
706725
map_ctx.add_field_path_element(element)
707726
ctx.add_errors(map_ctx)
708727

@@ -997,7 +1016,7 @@ def validate(self, ctx: ConstraintContext, message: message.Message):
9971016
constraint.validate(sub_ctx, v)
9981017
if sub_ctx.has_errors():
9991018
element = _field_to_element(self._field)
1000-
_set_path_element_map_key(element, k, self._key_field)
1019+
_set_path_element_map_key(element, k, self._key_field, self._value_field)
10011020
sub_ctx.add_field_path_element(element)
10021021
ctx.add_errors(sub_ctx)
10031022

0 commit comments

Comments
 (0)