Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't let uproot.update mess up the TFile fVersion #1212

Merged
merged 1 commit into from
May 9, 2024
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
4 changes: 3 additions & 1 deletion src/uproot/writing/_cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,8 +2159,10 @@ def deserialize(cls, raw_bytes, location):
uuid_bytes,
) = uproot.reading._file_header_fields_big.unpack(raw_bytes)
assert units == 8
outversion = version - 1000000
else:
assert units == 4
outversion = version

assert begin >= uproot.reading._file_header_fields_small.size
assert free_location >= 0
Expand All @@ -2183,7 +2185,7 @@ def deserialize(cls, raw_bytes, location):
info_num_bytes,
uuid.UUID(bytes=uuid_bytes),
)
out._version = version - 1000000
out._version = outversion
out._begin = begin
return out

Expand Down
18 changes: 18 additions & 0 deletions tests/test_1212_dont_let_update_mess_up_file_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import os

import uproot


def test(tmp_path):
filename = os.path.join(tmp_path, "whatever.root")

with uproot.recreate(filename) as file:
file["one"] = "one"

with uproot.update(filename) as file:
file["two"] = "two"

with uproot.open(filename) as file:
assert file.file.fVersion == uproot.writing._cascade.FileHeader.class_version