Fix null dereference in upserT