Inconsistent installation results with pip (python 3.9)

I’ve been using Github actions to CI test my config for some time now, but I recently updated the base image to use Python 3.9 and now I’m getting inconsistent results when I run hass. These appear to come from dependency requirements, but the odd thing is that when I run the same command immediately afterwards then it succeeds just fine. To my mind, if it fails then it should fail every time.

(hass-venv) root@e759a834b664:/# ${VENVDIR}/hass --script check_config --config /config/
INFO:homeassistant.util.package:Attempting install of colorlog==4.5.0
Testing configuration at /config/
INFO:homeassistant.util.package:Attempting install of home-assistant-frontend==20201229.1
INFO:homeassistant.util.package:Attempting install of aiohttp_cors==0.7.0
INFO:homeassistant.util.package:Attempting install of pillow==7.2.0
INFO:homeassistant.util.package:Attempting install of python-nest==4.1.0
INFO:homeassistant.util.package:Attempting install of google-nest-sdm==0.2.5
INFO:homeassistant.util.package:Attempting install of ha-ffmpeg==3.0.2
Fatal error while loading config: (idna 3.1 (/hass-venv/lib/python3.9/site-packages), Requirement.parse('idna<3,>=2.5'), {'requests'})
Failed config
  General Errors:
    - (idna 3.1 (/hass-venv/lib/python3.9/site-packages), Requirement.parse('idna<3,>=2.5'), {'requests'})

Successful config (partial)


(hass-venv) root@e759a834b664:/# ${VENVDIR}/hass --script check_config --config /config/
Testing configuration at /config/
WARNING:homeassistant.components.template.binary_sensor:The 'entity_id' option is deprecated, please remove it from your configuration
INFO:homeassistant.util.package:Attempting install of icmplib==2.0
INFO:homeassistant.util.package:Attempting install of distro==1.5.0
INFO:homeassistant.util.package:Attempting install of paho-mqtt==1.5.1
INFO:homeassistant.util.package:Attempting install of PyNaCl==1.3.0
INFO:homeassistant.util.package:Attempting install of emoji==0.5.4
INFO:homeassistant.util.package:Attempting install of hass-nabucasa==0.39.0
INFO:homeassistant.util.package:Attempting install of python-telegram-bot==13.1
INFO:homeassistant.util.package:Attempting install of PySocks==1.7.1
INFO:homeassistant.util.package:Attempting install of sqlalchemy==1.3.20
INFO:homeassistant.util.package:Attempting install of aiohue==2.1.0
INFO:homeassistant.util.package:Attempting install of defusedxml==0.6.0
INFO:homeassistant.util.package:Attempting install of netdisco==2.8.2
INFO:homeassistant.util.package:Attempting install of uvcclient==0.11.0
INFO:homeassistant.util.package:Attempting install of pykodi==0.2.1
INFO:homeassistant.util.package:Attempting install of wakeonlan
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
WARNING:homeassistant.components.template.sensor:The 'entity_id' option is deprecated, please remove it from your configuration
INFO:homeassistant.util.package:Attempting install of mutagen==1.45.1
INFO:homeassistant.util.package:Attempting install of gTTS==2.2.1
INFO:homeassistant.util.package:Attempting install of google-cloud-texttospeech==0.4.0
INFO:homeassistant.util.package:Attempting install of spotipy==2.16.1
INFO:homeassistant.util.package:Attempting install of pushbullet.py==0.11.0
INFO:homeassistant.util.package:Attempting install of pushover_complete==1.1.1
INFO:homeassistant.util.package:Attempting install of slackclient==2.5.0
INFO:homeassistant.util.package:Attempting install of pytradfri[async]==7.0.6
(hass-venv) root@e759a834b664:/# pip list | grep -E 'idna|requests'
idna                      2.10
requests                  2.25.0

Any suggestions would be gratefully received!

Edit: it seems I may have sorted this by always forcing a pip upgrade in my base image - if it do this then I can no longer replicate the issue.