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
10 changes: 8 additions & 2 deletions b2sdk/_internal/file_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,19 @@ def __init__(
self.mod_time_millis = self.upload_timestamp

@classmethod
def _decode_content_sha1(cls, content_sha1):
def _decode_content_sha1(cls, content_sha1: str | None) -> tuple[str | None, bool]:
if content_sha1 is None:
return None, True
if content_sha1.startswith(UNVERIFIED_CHECKSUM_PREFIX):
return content_sha1[len(UNVERIFIED_CHECKSUM_PREFIX) :], False
return content_sha1, True

@classmethod
def _encode_content_sha1(cls, content_sha1, content_sha1_verified):
def _encode_content_sha1(
cls, content_sha1: str | None, content_sha1_verified: bool
) -> str | None:
if content_sha1 is None:
return None
if not content_sha1_verified:
return f'{UNVERIFIED_CHECKSUM_PREFIX}{content_sha1}'
return content_sha1
Expand Down
1 change: 1 addition & 0 deletions changelog.d/553.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle null case when encoding / decoding `content_sha1` in BaseFileVersion.
8 changes: 8 additions & 0 deletions test/unit/file_version/test_file_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ def test_clone_file_version_and_download_version(self):
assert isinstance(cloned, DownloadVersion)
assert cloned.as_dict() == {**download_version.as_dict(), 'legalHold': LegalHold.OFF.value}

def test_clone_file_version_with_unknown_sha1(self):
cloned = self.file_version._clone(content_sha1=None)

assert isinstance(cloned, VFileVersion)
assert cloned.content_sha1 is None
assert cloned.content_sha1_verified is True
assert 'contentSha1' not in cloned.as_dict()

def test_update_legal_hold(self):
new_file_version = self.file_version.update_legal_hold(LegalHold.ON)
assert isinstance(new_file_version, VFileVersion)
Expand Down
Loading