Explicitly check the validity of the objects before asking for their elements in diff_root_files.py
See merge request !24861 (merged)