Prevent saving of detached models (see #6506)