Patch by @sergey. Note that this is really a bad thing actually, ideally we should never get that situation (IDs in Main referencing temp IDs outside of it). That can lead to many possible similar cases... Fixing that is not trivial though, so for now we'll have to live with it, until we have migrated *all* of our temp datablocks generation outside of Main's.