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
2 changes: 1 addition & 1 deletion pydantic_ai_slim/pydantic_ai/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ class FilePart:

def has_content(self) -> bool:
"""Return `True` if the file content is non-empty."""
return bool(self.content) # pragma: no cover
return bool(self.content.data)

__repr__ = _utils.dataclasses_no_defaults_repr

Expand Down
8 changes: 8 additions & 0 deletions tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,14 @@ def test_pre_usage_refactor_messages_deserializable():
)


def test_file_part_has_content():
filepart = FilePart(content=BinaryContent(data=b'', media_type='application/pdf'))
assert not filepart.has_content()

filepart.content.data = b'not empty'
assert filepart.has_content()


def test_file_part_serialization_roundtrip():
# Verify that a serialized BinaryImage doesn't come back as a BinaryContent.
messages: list[ModelMessage] = [
Expand Down