Fix ValueError: invalid operation on closed shelf #2691