You just don't have the full picture.
There is only one unit: the one that is being upgraded. At the moment you click on it to order it to upgrade the unit instantly changes its unit-type and begins the upgrade animation. If you check its unit-type it will change once the upgrade begins but never again (because it's already the new type). The unit itself never goes anywhere (it isn't literally replaced) so there is no other unit to refer to.
If you want to learn the unit-type the unit used to be before the upgrade, you will have to either detect the order the instant it is given or build a database (hashtable) to return parent buildings. The approaches differ so it's important to ask directly: why do you need to know this? When will this information be used? What are you trying to achieve? Perhaps there is a better or more straightforward way. The order might be the easiest method but I'm not certain it works because the upgrade orders are effectively instant.