Skip to content

Commit

Permalink
fix: don't let uproot.update mess up the TFile fVersion (#1212)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski authored May 9, 2024
1 parent e944099 commit 2c7099d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit 2c7099d

Please sign in to comment.