versions: unload constant before calling Formula.factory

Closes #18634.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>