diff --git a/src/uproot/writing/_cascade.py b/src/uproot/writing/_cascade.py index d790788b7..fc37e4a45 100644 --- a/src/uproot/writing/_cascade.py +++ b/src/uproot/writing/_cascade.py @@ -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 @@ -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 diff --git a/tests/test_1212_dont_let_update_mess_up_file_version.py b/tests/test_1212_dont_let_update_mess_up_file_version.py new file mode 100644 index 000000000..e5913a43a --- /dev/null +++ b/tests/test_1212_dont_let_update_mess_up_file_version.py @@ -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