Fix for RuntimeError during upgrade