Skip to content
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
38 changes: 19 additions & 19 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion protovalidate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
validate = _validator.validate
collect_violations = _validator.collect_violations

__all__ = ["Validator", "CompilationError", "ValidationError", "Violations", "validate", "collect_violations"]
__all__ = ["CompilationError", "ValidationError", "Validator", "Violations", "collect_violations", "validate"]
6 changes: 4 additions & 2 deletions protovalidate/internal/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,10 @@ def __init__(
self._ignore_empty = (
field_level.ignore_empty
or field_level.ignore in (validate_pb2.IGNORE_IF_UNPOPULATED, validate_pb2.IGNORE_IF_DEFAULT_VALUE)
or field.has_presence # type: ignore[attr-defined]
and not for_items
or (
field.has_presence # type: ignore[attr-defined]
and not for_items
)
Comment on lines +350 to +353
Copy link
Member

Choose a reason for hiding this comment

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

@jchadwick-buf semantically this shouldn't have changed, just confirming this is the intended grouping here?

Copy link

@ghost ghost Nov 25, 2024

Choose a reason for hiding this comment

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

Yes sounds right. The basic idea is that if a field has presence, then it should default to being ignored when empty. However, for_items is set if we're running against a value nested under a repeated field. So if for_items is true, then we don't want to ignore empty on the zero value. (This probably seems impossible and I think it only comes into account in a very weird edge case.)

)
self._ignore_default = field.has_presence and field_level.ignore == validate_pb2.IGNORE_IF_DEFAULT_VALUE # type: ignore[attr-defined]
self._required = field_level.required
Expand Down
Loading