Got this issue when I was loading a key in a fresh Docker Container.
after 2nd call to the function the key fingerprint was valid.
That happens because the stdout in this case is:
gpg: directory /root/.gnupg' created gpg: new configuration file /root/.gnupg/gpg.conf' created
gpg: WARNING: options in /root/.gnupg/gpg.conf' are not yet active during this run gpg: keyring /root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created