Skip to content
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion protovalidate/internal/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import celpy
from celpy import celtypes
from google.protobuf import any_pb2, descriptor, duration_pb2, message, message_factory, timestamp_pb2
from google.protobuf import any_pb2, descriptor, duration_pb2, message, message_factory, timestamp_pb2, unknown_fields # type: ignore[attr-defined]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

From what I can see, this API (google.protobuf.unknown_fields) was added in 4.21.0.
There are no stubs in types-protobuf though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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


from buf.validate import validate_pb2
from protovalidate.internal.cel_field_presence import InterpretedRunner, in_has
Expand Down Expand Up @@ -565,6 +565,9 @@ def __init__(
self._required = field_level.required
if type_case is not None:
rules: message.Message = getattr(field_level, type_case)
if len(unknown_fields.UnknownFieldSet(rules)) > 0:
msg = f"unknown rules in {rules.DESCRIPTOR.full_name}"
raise CompilationError(msg)
# For each set field in the message, look for the private rule
# extension.
for list_field, _ in rules.ListFields():
Expand Down Expand Up @@ -1031,6 +1034,9 @@ def _new_scalar_field_rule(
check_field_type(field, 0, "google.protobuf.Any")
result = AnyRules(self._env, self._funcs, field, field_level)
return result
else:
msg = f"unknown rule type {type_case!r}"
raise CompilationError(msg)

def _new_field_rule(
self,
Expand Down
Loading